Accept direct Soundcloud URL instead of data from API to share Soundcloud tracks

This commit is contained in:
Nicolas Rosset 2021-04-02 18:11:06 +02:00
parent 586ad0e722
commit fdd2ad61c3
1 changed files with 36 additions and 31 deletions

View File

@ -2316,6 +2316,7 @@ tarteaucitron.services.soundcloud = {
frame_height = 'height="' + player_height + '" ', frame_height = 'height="' + player_height + '" ',
playable_id = x.getAttribute('data-playable-id'), playable_id = x.getAttribute('data-playable-id'),
playable_type = x.getAttribute('data-playable-type'), playable_type = x.getAttribute('data-playable-type'),
data_playable_url = x.getAttribute('data-playable-url'),
color = x.getAttribute('data-color'), color = x.getAttribute('data-color'),
autoplay = x.getAttribute('data-auto-play'), autoplay = x.getAttribute('data-auto-play'),
hideRelated = x.getAttribute('data-hide-related'), hideRelated = x.getAttribute('data-hide-related'),
@ -2328,11 +2329,15 @@ tarteaucitron.services.soundcloud = {
var allowAutoplay = autoplay === 'true' ? 'allow="autoplay"' : ''; var allowAutoplay = autoplay === 'true' ? 'allow="autoplay"' : '';
if (playable_id === undefined) { if (playable_id === undefined && data_playable_url === undefined) {
return ""; return "";
} }
// Allow to embed from API results (playable_type + playable_id)
var qs = '?url=https%3A//api.soundcloud.com/' + playable_type + '/' + playable_id; var qs = '?url=https%3A//api.soundcloud.com/' + playable_type + '/' + playable_id;
// Or from raw URL from Soundcloud website
if (data_playable_url && data_playable_url.length >0) qs = '?url=' + escape(data_playable_url);
if (hideRelated && hideRelated.length > 0) qs += '&hide_related=' + hideRelated; if (hideRelated && hideRelated.length > 0) qs += '&hide_related=' + hideRelated;
if (color && color.length > 0) qs += '&color=' + color.replace('#', '%23'); if (color && color.length > 0) qs += '&color=' + color.replace('#', '%23');
if (autoplay && autoplay.length > 0) qs += '&auto_play=' + autoplay; if (autoplay && autoplay.length > 0) qs += '&auto_play=' + autoplay;