Skip to content

Commit

Permalink
MediaEmbed: added support for private playlists in SoundCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Jun 10, 2022
1 parent 36ee9ff commit e0fab77
Show file tree
Hide file tree
Showing 10 changed files with 2,533 additions and 30 deletions.
2,493 changes: 2,492 additions & 1 deletion docs/testdox.txt

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/Bundles/Fatdown.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Bundles/Fatdown/Renderer.php

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Bundles/Forum.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Bundles/Forum/Renderer.php

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/Bundles/MediaPack.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Bundles/MediaPack/Renderer.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CachedDefinitionCollection extends SiteDefinitionCollection
'scribd'=>['attributes'=>[],'example'=>['https://www.scribd.com/doc/237147661/Calculus-2-Test-1-Review','https://www.scribd.com/presentation/324333881/600-1450-World-History-Jeopardy'],'extract'=>['!scribd\\.com/(?:mobile/)?(?:doc(?:ument)?|presentation)/(?\'id\'\\d+)!'],'homepage'=>'https://www.scribd.com/','host'=>['scribd.com'],'iframe'=>['height'=>500,'src'=>'https://www.scribd.com/embeds/{@id}/content?view_mode=scroll&show_recommendations=false','style'=>['resize'=>'vertical'],'width'=>'100%'],'name'=>'Scribd','scrape'=>[],'tags'=>['documents','presentations']],
'sendvid'=>['attributes'=>[],'example'=>'https://sendvid.com/w99u3jjp','extract'=>['!sendvid\\.com/(?\'id\'\\w+)!'],'homepage'=>'https://www.sendvid.com/','host'=>['sendvid.com'],'iframe'=>['src'=>'//sendvid.com/embed/{@id}'],'name'=>'Sendvid','scrape'=>[],'tags'=>['videos']],
'slideshare'=>['attributes'=>[],'example'=>'https://www.slideshare.net/Slideshare/how-23431564','extract'=>['!slideshare\\.net/[^/]+/[-\\w]+-(?\'id\'\\d{6,})$!'],'homepage'=>'https://www.slideshare.net/','host'=>['slideshare.net'],'iframe'=>['height'=>356,'src'=>'//www.slideshare.net/slideshow/embed_code/{@id}','width'=>427],'name'=>'SlideShare','scrape'=>[['extract'=>['!"presentationId":(?\'id\'\\d+)!'],'match'=>['@slideshare\\.net/[^/]+/\\w(?![-\\w]+-\\d{6,}$)@']]],'source'=>'http://help.slideshare.com/forums/67665-Embedding-Sharing','tags'=>['presentations']],
'soundcloud'=>['amp'=>['custom-element'=>'amp-soundcloud','src'=>'https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js','template'=>'<amp-soundcloud layout="fixed-height" height="150" data-playlistid="{@playlist_id}" data-secret-token="{@secret_token}" data-trackid="{@track_id}"/>'],'attributes'=>[],'example'=>['https://api.soundcloud.com/tracks/98282116','https://soundcloud.com/andrewbird/three-white-horses','https://soundcloud.com/tenaciousd/sets/rize-of-the-fenix/'],'extract'=>['@https?://(?:api\\.)?soundcloud\\.com/(?!pages/)(?\'id\'[-/\\w]+/[-/\\w]+|^[^/]+/[^/]+$)@i','@api\\.soundcloud\\.com/playlists/(?\'playlist_id\'\\d+)@','@api\\.soundcloud\\.com/tracks/(?\'track_id\'\\d+)(?:\\?secret_token=(?\'secret_token\'[-\\w]+))?@','@soundcloud\\.com/(?!playlists|tracks)[-\\w]+/[-\\w]+/(?=s-)(?\'secret_token\'[-\\w]+)@'],'homepage'=>'https://soundcloud.com/','host'=>['soundcloud.com'],'iframe'=>['height'=>'<xsl:choose><xsl:when test="@playlist_id or contains(@id,\'/sets/\')">450</xsl:when><xsl:otherwise>166</xsl:otherwise></xsl:choose>','max-width'=>900,'src'=>'https://w.soundcloud.com/player/?url=<xsl:choose><xsl:when test="@playlist_id">https%3A//api.soundcloud.com/playlists/<xsl:value-of select="@playlist_id"/></xsl:when><xsl:when test="@track_id">https%3A//api.soundcloud.com/tracks/<xsl:value-of select="@track_id"/>&amp;secret_token=<xsl:value-of select="@secret_token"/></xsl:when><xsl:otherwise><xsl:if test="not(contains(@id,\'://\'))">https%3A//soundcloud.com/</xsl:if><xsl:value-of select="@id"/></xsl:otherwise></xsl:choose>','width'=>'100%'],'name'=>'SoundCloud','scrape'=>[['extract'=>['@soundcloud:tracks:(?\'track_id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@soundcloud\\.com/(?!playlists/\\d|tracks/\\d)[-\\w]+/[-\\w]@']],['extract'=>['@soundcloud://playlists:(?\'playlist_id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@soundcloud\\.com/[-\\w]+/sets/@']]],'source'=>'https://soundcloud.com/pages/widgets','tags'=>['music']],
'soundcloud'=>['amp'=>['custom-element'=>'amp-soundcloud','src'=>'https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js','template'=>'<amp-soundcloud layout="fixed-height" height="150" data-playlistid="{@playlist_id}" data-secret-token="{@secret_token}" data-trackid="{@track_id}"/>'],'attributes'=>[],'example'=>['https://api.soundcloud.com/tracks/98282116','https://soundcloud.com/andrewbird/three-white-horses','https://soundcloud.com/tenaciousd/sets/rize-of-the-fenix/'],'extract'=>['@https?://(?:api\\.)?soundcloud\\.com/(?!pages/)(?\'id\'[-/\\w]+/[-/\\w]+|^[^/]+/[^/]+$)@i','@api\\.soundcloud\\.com/playlists/(?\'playlist_id\'\\d+)@','@api\\.soundcloud\\.com/tracks/(?\'track_id\'\\d+)(?:\\?secret_token=(?\'secret_token\'[-\\w]+))?@','@soundcloud\\.com/(?!playlists/|tracks/)[-\\w]+/(?:sets/)?[-\\w]+/(?=s-)(?\'secret_token\'[-\\w]+)@'],'homepage'=>'https://soundcloud.com/','host'=>['soundcloud.com'],'iframe'=>['height'=>'<xsl:choose><xsl:when test="@playlist_id or contains(@id,\'/sets/\')">450</xsl:when><xsl:otherwise>166</xsl:otherwise></xsl:choose>','max-width'=>900,'src'=>'https://w.soundcloud.com/player/?url=<xsl:choose><xsl:when test="@playlist_id">https%3A//api.soundcloud.com/playlists/<xsl:value-of select="@playlist_id"/>%3Fsecret_token%3D<xsl:value-of select="@secret_token"/></xsl:when><xsl:when test="@track_id">https%3A//api.soundcloud.com/tracks/<xsl:value-of select="@track_id"/>%3Fsecret_token%3D<xsl:value-of select="@secret_token"/></xsl:when><xsl:otherwise><xsl:if test="not(contains(@id,\'://\'))">https%3A//soundcloud.com/</xsl:if><xsl:value-of select="@id"/></xsl:otherwise></xsl:choose>','width'=>'100%'],'name'=>'SoundCloud','scrape'=>[['extract'=>['@soundcloud(?::/)?:tracks:(?\'track_id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@soundcloud\\.com/(?!playlists/\\d|tracks/\\d)[-\\w]+/[-\\w]@']],['extract'=>['@soundcloud(?::/)?/playlists:(?\'playlist_id\'\\d+)@'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['@soundcloud\\.com/[-\\w]+/sets/@']]],'source'=>'https://soundcloud.com/pages/widgets','tags'=>['music']],
'sporcle'=>['attributes'=>[],'example'=>'https://www.sporcle.com/games/bowsntoys/mothers-day-jokes','extract'=>['#sporcle.com/framed/.*?gid=(?\'id\'\\w+)#'],'homepage'=>'https://www.sporcle.com/','host'=>['sporcle.com'],'iframe'=>['data-s9e-livepreview-ignore-attrs'=>'style','height'=>535,'onload'=>'var c=new MessageChannel;c.port1.onmessage=function(e){{style.height=e.data+\'px\'}};contentWindow.postMessage(\'s9e:init\',\'*\',[c.port2])','src'=>'https://s9e.github.io/iframe/2/sporcle.min.html#{@id}','width'=>820],'name'=>'Sporcle','scrape'=>[['extract'=>['#encodedGameID\\W+(?\'id\'\\w+)#'],'match'=>['#sporcle\\.com/games/(?!\\w*category/)[-\\w]+/[-\\w]#']]],'tags'=>['entertainment']],
'sportsnet'=>['attributes'=>[],'example'=>'https://www.sportsnet.ca/soccer/west-ham-2-hull-2/','extract'=>[],'homepage'=>'https://www.sportsnet.ca/','host'=>['sportsnet.ca'],'iframe'=>['src'=>'//players.brightcove.net/1704050871/rkedLxwfab_default/index.html?videoId={@id}'],'name'=>'Sportsnet','scrape'=>[['extract'=>['@bc_videos\\s*:\\s*(?\'id\'\\d+)@'],'match'=>['//']]],'tags'=>['.ca','sports']],
'spotify'=>['attributes'=>[],'choose'=>['otherwise'=>['iframe'=>['allow'=>'encrypted-media','height'=>320,'padding-height'=>80,'src'=>'https://open.spotify.com/embed/{translate(@id,\':\',\'/\')}{@path}','width'=>320]],'when'=>['iframe'=>['allow'=>'encrypted-media','height'=>152,'max-width'=>900,'src'=>'https://open.spotify.com/embed/{@id}','width'=>'100%'],'test'=>'starts-with(@id, \'episode/\') or starts-with(@id, \'show/\')']],'example'=>['https://open.spotify.com/user/ryan.lloyd.french/playlist/4jHNeLTj7CnL5JwZzmnqOL','https://open.spotify.com/track/3CPjqkaMwrbht1lJpELoY0?si=K7cm7-dWTR6U7BjDn1oP7g','https://open.spotify.com/episode/4zhSJwkVdndcVvwCypfl9b'],'extract'=>['!(?:open|play)\\.spotify\\.com/(?:user/[-.\\w]+/)?(?\'id\'(?:album|artist|episode|playlist|show|track)(?:[:/][-.\\w]+)+)!'],'homepage'=>'https://www.spotify.com/','host'=>['link.tospotify.com','open.spotify.com','play.spotify.com'],'name'=>'Spotify','scrape'=>[['extract'=>['!(?:open|play)\\.spotify\\.com/(?:user/[-.\\w]+/)?(?\'id\'(?:album|artist|episode|playlist|show|track)(?:[:/][-.\\w]+)+)!'],'header'=>'User-agent: PHP (not Mozilla)','match'=>['!link\\.tospotify\\.com/.!']]],'source'=>'https://developer.spotify.com/technologies/widgets/spotify-play-button/','tags'=>['music','podcasts']],
Expand Down
10 changes: 6 additions & 4 deletions src/Plugins/MediaEmbed/Configurator/sites/soundcloud.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
<extract>@https?://(?:api\.)?soundcloud\.com/(?!pages/)(?'id'[-/\w]+/[-/\w]+|^[^/]+/[^/]+$)@i</extract>
<extract>@api\.soundcloud\.com/playlists/(?'playlist_id'\d+)@</extract>
<extract>@api\.soundcloud\.com/tracks/(?'track_id'\d+)(?:\?secret_token=(?'secret_token'[-\w]+))?@</extract>
<extract>@soundcloud\.com/(?!playlists|tracks)[-\w]+/[-\w]+/(?=s-)(?'secret_token'[-\w]+)@</extract>
<extract>@soundcloud\.com/(?!playlists/|tracks/)[-\w]+/(?:sets/)?[-\w]+/(?=s-)(?'secret_token'[-\w]+)@</extract>
<scrape>
<header>User-agent: PHP (not Mozilla)</header>
<match>@soundcloud\.com/(?!playlists/\d|tracks/\d)[-\w]+/[-\w]@</match>
<extract>@soundcloud:tracks:(?'track_id'\d+)@</extract>
<extract>@soundcloud(?::/)?:tracks:(?'track_id'\d+)@</extract>
</scrape>
<scrape>
<header>User-agent: PHP (not Mozilla)</header>
<match>@soundcloud\.com/[-\w]+/sets/@</match>
<extract>@soundcloud://playlists:(?'playlist_id'\d+)@</extract>
<extract>@soundcloud(?::/)?/playlists:(?'playlist_id'\d+)@</extract>
</scrape>
<iframe width="100%" max-width="900">
<height><![CDATA[
Expand All @@ -34,11 +34,13 @@
<xsl:when test="@playlist_id">
<xsl:text>https%3A//api.soundcloud.com/playlists/</xsl:text>
<xsl:value-of select="@playlist_id"/>
<xsl:text>%3Fsecret_token%3D</xsl:text>
<xsl:value-of select="@secret_token"/>
</xsl:when>
<xsl:when test="@track_id">
<xsl:text>https%3A//api.soundcloud.com/tracks/</xsl:text>
<xsl:value-of select="@track_id"/>
<xsl:text>&amp;secret_token=</xsl:text>
<xsl:text>%3Fsecret_token%3D</xsl:text>
<xsl:value-of select="@secret_token"/>
</xsl:when>
<xsl:otherwise>
Expand Down
14 changes: 12 additions & 2 deletions tests/Plugins/MediaEmbed/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ function ($configurator)
],
[
'https://soundcloud.com/user-56185579/sets/deep-impact-for-u-he-zebra-2',
'<r><SOUNDCLOUD id="user-56185579/sets/deep-impact-for-u-he-zebra-2" playlist_id="1227667873" track_id="1009549597">https://soundcloud.com/user-56185579/sets/deep-impact-for-u-he-zebra-2</SOUNDCLOUD></r>',
'<r><SOUNDCLOUD id="user-56185579/sets/deep-impact-for-u-he-zebra-2" playlist_id="1227667873" track_id="1009554946">https://soundcloud.com/user-56185579/sets/deep-impact-for-u-he-zebra-2</SOUNDCLOUD></r>',
[],
function ($configurator)
{
Expand All @@ -1252,6 +1252,16 @@ function ($configurator)
$configurator->MediaEmbed->add('soundcloud');
}
],
[
'https://soundcloud.com/subsineacademy/sets/aphelion-bora/s-ntU3imOJop1',
'<r><SOUNDCLOUD id="subsineacademy/sets/aphelion-bora/s-ntU3imOJop1" playlist_id="1391797690" secret_token="s-ntU3imOJop1" track_id="1211369659">https://soundcloud.com/subsineacademy/sets/aphelion-bora/s-ntU3imOJop1</SOUNDCLOUD></r>',
[],
function ($configurator)
{
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../../.cache';
$configurator->MediaEmbed->add('soundcloud');
}
],
[
'https://www.sporcle.com/games/eyes355/find-five-countries',
'<r><SPORCLE id="15d32a898365">https://www.sporcle.com/games/eyes355/find-five-countries</SPORCLE></r>',
Expand Down Expand Up @@ -1583,7 +1593,7 @@ function ($configurator)
],
[
'https://soundcloud.com/andrewbird/three-white-horses',
'<iframe data-s9e-mediaembed="soundcloud" allowfullscreen="" loading="lazy" scrolling="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/59509713&amp;secret_token=" style="border:0;height:166px;max-width:900px;width:100%"></iframe>',
'<iframe data-s9e-mediaembed="soundcloud" allowfullscreen="" loading="lazy" scrolling="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/59509713%3Fsecret_token%3D" style="border:0;height:166px;max-width:900px;width:100%"></iframe>',
[],
function ($configurator)
{
Expand Down

0 comments on commit e0fab77

Please sign in to comment.