Skip to content

Commit

Permalink
Merge pull request #16 from Alixt0/feature/spotify-integration
Browse files Browse the repository at this point in the history
Add Spotify compatibility
  • Loading branch information
nicolashmln authored Jul 7, 2023
2 parents 4af77c8 + 84216f5 commit 989a974
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Strapi plugin oEmbed

Embed content from third party sites (Youtube, Vimeo, Tiktok, Soundcloud, ...) for https://strapi.io v4 (For strapi v3 use v0.4.0)
Embed content from third party sites (Youtube, Vimeo, Tiktok, Soundcloud, Spotify...) for https://strapi.io v4 (For strapi v3 use v0.4.0)

![](demo.gif)

Expand Down Expand Up @@ -86,6 +86,7 @@ If you paste the url `https://www.youtube.com/watch?v=tkiOqSTVGds` in the modal,
- Vimeo
- Tiktok
- Soundcloud
- Spotify

Feel free to submit a PR with the provider you want, you just have to edit this file: `server/services/oembed.js`.

Expand Down
2 changes: 1 addition & 1 deletion admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"form.button.delete": "Delete",
"modal.import.title": "Import oEmbed content",
"modal.import.input.label": "URL",
"modal.import.input.description": "Youtube, Vimeo, Tiktok or Soundcloud",
"modal.import.input.description": "Youtube, Vimeo, Tiktok, Soundcloud or Spotify",
"modal.import.button.import": "Import"
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "strapi-plugin-oembed",
"version": "1.0.1",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud...) in Strapi",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud, Spotify...) in Strapi",
"strapi": {
"name": "oembed",
"displayName": "oEmbed",
"icon": "globe-asia",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud...) in Strapi",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud, Spotify...) in Strapi",
"kind": "plugin"
},
"dependencies": {},
Expand All @@ -28,7 +28,8 @@
"youtube",
"vimeo",
"tiktok",
"soundcloud"
"soundcloud",
"spotify"
],
"peerDependencies": {
"@strapi/strapi": "^4.4.0"
Expand Down
9 changes: 8 additions & 1 deletion server/services/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = (
async fetch(url) {
let data;

const matches = url.match(/^(https?:\/\/)?(www\.)?(youtu\.be|youtube\.com|soundcloud\.com|vimeo\.com|tiktok\.com)/i);
const matches = url.match(/^(https?:\/\/)?(www\.)?(youtu\.be|youtube\.com|soundcloud\.com|vimeo\.com|tiktok\.com|open\.spotify\.com)/i);

if (matches) {
try {
Expand Down Expand Up @@ -54,6 +54,13 @@ module.exports = (
mime = 'video/tiktok';
thumbnail = fetchedData.thumbnail_url;
break;

case 'open.spotify.com':
fetchedData = await axios.get(`https://open.spotify.com/oembed?url=${encodeURIComponent(url)}`).then(res => res.data);
title = fetchedData.title;
mime = 'audio/spotify';
thumbnail = fetchedData.thumbnail_url;
break;

default:
break;
Expand Down

0 comments on commit 989a974

Please sign in to comment.