Skip to content

Commit

Permalink
[soundcloud] add support for token protected embeds(#18954)
Browse files Browse the repository at this point in the history
  • Loading branch information
remitamine authored and pareronia committed Jun 22, 2020
1 parent 3538009 commit 440408a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions youtube_dl/extractor/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@


class SoundcloudEmbedIE(InfoExtractor):
_VALID_URL = r'https?://(?:w|player|p)\.soundcloud\.com/player/?.*?url=(?P<id>.*)'
_VALID_URL = r'https?://(?:w|player|p)\.soundcloud\.com/player/?.*?\burl=(?P<id>.+)'
_TEST = {
# from https://www.soundi.fi/uutiset/ennakkokuuntelussa-timo-kaukolammen-station-to-station-to-station-julkaisua-juhlitaan-tanaan-g-livelabissa/
'url': 'https://w.soundcloud.com/player/?visual=true&url=https%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F922213810&show_artwork=true&maxwidth=640&maxheight=960&dnt=1&secret_token=s-ziYey',
'only_matching': True,
}

@staticmethod
def _extract_urls(webpage):
Expand All @@ -37,8 +42,13 @@ def _extract_urls(webpage):
webpage)]

def _real_extract(self, url):
return self.url_result(compat_urlparse.parse_qs(
compat_urlparse.urlparse(url).query)['url'][0])
query = compat_urlparse.parse_qs(
compat_urlparse.urlparse(url).query)
api_url = query['url'][0]
secret_token = query.get('secret_token')
if secret_token:
api_url = update_url_query(api_url, {'secret_token': secret_token[0]})
return self.url_result(api_url)


class SoundcloudIE(InfoExtractor):
Expand Down

0 comments on commit 440408a

Please sign in to comment.