[soundcloud] Add related tracks extractor (#1000)

Authored by: Lapin0t
This commit is contained in:
Lapinot 2021-12-20 02:14:19 +01:00 committed by GitHub
parent e75bb0d6c3
commit c2dedf12e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View File

@ -1357,6 +1357,7 @@ from .soundcloud import (
SoundcloudEmbedIE, SoundcloudEmbedIE,
SoundcloudIE, SoundcloudIE,
SoundcloudSetIE, SoundcloudSetIE,
SoundcloudRelatedIE,
SoundcloudUserIE, SoundcloudUserIE,
SoundcloudTrackStationIE, SoundcloudTrackStationIE,
SoundcloudPlaylistIE, SoundcloudPlaylistIE,

View File

@ -214,8 +214,9 @@ class SoundcloudIE(SoundcloudBaseIE):
(?!stations/track) (?!stations/track)
(?P<uploader>[\w\d-]+)/ (?P<uploader>[\w\d-]+)/
(?!(?:tracks|albums|sets(?:/.+?)?|reposts|likes|spotlight)/?(?:$|[?#])) (?!(?:tracks|albums|sets(?:/.+?)?|reposts|likes|spotlight)/?(?:$|[?#]))
(?P<title>[\w\d-]+)/? (?P<title>[\w\d-]+)
(?P<token>[^?]+?)?(?:[?].*)?$) (?:/(?P<token>(?!(?:albums|sets|recommended))[^?]+?))?
(?:[?].*)?$)
|(?:api(?:-v2)?\.soundcloud\.com/tracks/(?P<track_id>\d+) |(?:api(?:-v2)?\.soundcloud\.com/tracks/(?P<track_id>\d+)
(?:/?\?secret_token=(?P<secret_token>[^&]+))?) (?:/?\?secret_token=(?P<secret_token>[^&]+))?)
) )
@ -827,6 +828,54 @@ class SoundcloudTrackStationIE(SoundcloudPagedPlaylistBaseIE):
track_id, 'Track station: %s' % track['title']) track_id, 'Track station: %s' % track['title'])
class SoundcloudRelatedIE(SoundcloudPagedPlaylistBaseIE):
_VALID_URL = r'https?://(?:(?:www|m)\.)?soundcloud\.com/(?P<slug>[\w\d-]+/[\w\d-]+)/(?P<relation>albums|sets|recommended)'
IE_NAME = 'soundcloud:related'
_TESTS = [{
'url': 'https://soundcloud.com/wajang/sexapil-pingers-5/recommended',
'info_dict': {
'id': '1084577272',
'title': 'Sexapil - Pingers 5 (Recommended)',
},
'playlist_mincount': 50,
}, {
'url': 'https://soundcloud.com/wajang/sexapil-pingers-5/albums',
'info_dict': {
'id': '1084577272',
'title': 'Sexapil - Pingers 5 (Albums)',
},
'playlist_mincount': 1,
}, {
'url': 'https://soundcloud.com/wajang/sexapil-pingers-5/sets',
'info_dict': {
'id': '1084577272',
'title': 'Sexapil - Pingers 5 (Sets)',
},
'playlist_mincount': 4,
}]
_BASE_URL_MAP = {
'albums': 'tracks/%s/albums',
'sets': 'tracks/%s/playlists_without_albums',
'recommended': 'tracks/%s/related',
}
def _real_extract(self, url):
slug, relation = self._match_valid_url(url).group('slug', 'relation')
track = self._download_json(
self._resolv_url(self._BASE_URL + slug),
slug, 'Downloading track info', headers=self._HEADERS)
if track.get('errors'):
raise ExtractorError(f'{self.IE_NAME} said: %s' % ','.join(
str(err['error_message']) for err in track['errors']), expected=True)
return self._extract_playlist(
self._API_V2_BASE + self._BASE_URL_MAP[relation] % track['id'], str(track['id']),
'%s (%s)' % (track.get('title') or slug, relation.capitalize()))
class SoundcloudPlaylistIE(SoundcloudPlaylistBaseIE): class SoundcloudPlaylistIE(SoundcloudPlaylistBaseIE):
_VALID_URL = r'https?://api(?:-v2)?\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$' _VALID_URL = r'https?://api(?:-v2)?\.soundcloud\.com/playlists/(?P<id>[0-9]+)(?:/?\?secret_token=(?P<token>[^&]+?))?$'
IE_NAME = 'soundcloud:playlist' IE_NAME = 'soundcloud:playlist'