diff --git a/README.md b/README.md index b06374f..82e8953 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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`. diff --git a/admin/src/translations/en.json b/admin/src/translations/en.json index f7aab87..eb2a365 100644 --- a/admin/src/translations/en.json +++ b/admin/src/translations/en.json @@ -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" } diff --git a/package.json b/package.json index 6544129..58a21a0 100644 --- a/package.json +++ b/package.json @@ -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": {}, @@ -28,7 +28,8 @@ "youtube", "vimeo", "tiktok", - "soundcloud" + "soundcloud", + "spotify" ], "peerDependencies": { "@strapi/strapi": "^4.4.0" diff --git a/server/services/oembed.js b/server/services/oembed.js index e61e510..07f789d 100644 --- a/server/services/oembed.js +++ b/server/services/oembed.js @@ -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 { @@ -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;