[audius] Fix extractor

This commit is contained in:
pukkandan 2021-02-01 14:58:15 +05:30
parent 82e3f6ebda
commit c55256c5a3
3 changed files with 35 additions and 7 deletions

View File

@ -80,8 +80,9 @@
- **AudioBoom** - **AudioBoom**
- **audiomack** - **audiomack**
- **audiomack:album** - **audiomack:album**
- **Audius** - **Audius**: Audius.co
- **audius:playlist** - **audius:playlist**: Audius.co playlists
- **audius:track**: Audius track ID or API link. Prepend with "audius:"
- **AWAAN** - **AWAAN**
- **awaan:live** - **awaan:live**
- **awaan:season** - **awaan:season**

View File

@ -76,6 +76,7 @@ class AudiusBaseIE(InfoExtractor):
class AudiusIE(AudiusBaseIE): class AudiusIE(AudiusBaseIE):
_VALID_URL = r'''(?x)https?://(?:www\.)?(?:audius\.co/(?P<uploader>[\w\d-]+)(?!/album|/playlist)/(?P<title>\S+))''' _VALID_URL = r'''(?x)https?://(?:www\.)?(?:audius\.co/(?P<uploader>[\w\d-]+)(?!/album|/playlist)/(?P<title>\S+))'''
IE_DESC = 'Audius.co'
_TESTS = [ _TESTS = [
{ {
# URL from Chrome address bar which replace backslash to forward slash # URL from Chrome address bar which replace backslash to forward slash
@ -124,11 +125,15 @@ class AudiusIE(AudiusBaseIE):
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
uploader, title, track_id = mobj.groups() track_id = try_get(mobj, lambda x: x.group('track_id'))
if track_id is None: if track_id is None:
title = mobj.group('title')
# uploader = mobj.group('uploader')
url = self._prepare_url(url, title) url = self._prepare_url(url, title)
track_data = self._resolve_url(url, title) track_data = self._resolve_url(url, title)
else: # API link else: # API link
title = None
# uploader = None
track_data = self._api_request('/tracks/%s' % track_id, track_id) track_data = self._api_request('/tracks/%s' % track_id, track_id)
if not isinstance(track_data, dict): if not isinstance(track_data, dict):
@ -167,9 +172,26 @@ class AudiusIE(AudiusBaseIE):
} }
class AudiusTrackIE(AudiusIE):
_VALID_URL = r'''(?x)(?:audius:)(?:https?://(?:www\.)?.+/v1/tracks/)?(?P<track_id>\w+)'''
IE_NAME = 'audius:track'
IE_DESC = 'Audius track ID or API link. Prepend with "audius:"'
_TESTS = [
{
'url': 'audius:9RWlo',
'only_matching': True
},
{
'url': 'audius:http://discoveryprovider.audius.prod-us-west-2.staked.cloud/v1/tracks/9RWlo',
'only_matching': True
},
]
class AudiusPlaylistIE(AudiusBaseIE): class AudiusPlaylistIE(AudiusBaseIE):
_VALID_URL = r'https?://(?:www\.)?audius\.co/(?P<uploader>[\w\d-]+)/(?:album|playlist)/(?P<title>\S+)' _VALID_URL = r'https?://(?:www\.)?audius\.co/(?P<uploader>[\w\d-]+)/(?:album|playlist)/(?P<title>\S+)'
IE_NAME = 'audius:playlist' IE_NAME = 'audius:playlist'
IE_DESC = 'Audius.co playlists'
_TEST = { _TEST = {
'url': 'https://audius.co/test_acc/playlist/test-playlist-22910', 'url': 'https://audius.co/test_acc/playlist/test-playlist-22910',
'info_dict': { 'info_dict': {
@ -189,14 +211,15 @@ class AudiusPlaylistIE(AudiusBaseIE):
if not track_id: if not track_id:
raise ExtractorError('Unable to get track ID from playlist') raise ExtractorError('Unable to get track ID from playlist')
entries.append(self.url_result( entries.append(self.url_result(
'%s%s/tracks/%s' % (self._API_BASE, self._API_V, track_id), 'audius:%s' % track_id,
ie=AudiusIE.ie_key(), video_id=track_id)) ie=AudiusTrackIE.ie_key(), video_id=track_id))
return entries return entries
def _real_extract(self, url): def _real_extract(self, url):
self._select_api_base() self._select_api_base()
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
uploader, title = mobj.groups() title = mobj.group('title')
# uploader = mobj.group('uploader')
url = self._prepare_url(url, title) url = self._prepare_url(url, title)
playlist_response = self._resolve_url(url, title) playlist_response = self._resolve_url(url, title)

View File

@ -90,7 +90,11 @@ from .atvat import ATVAtIE
from .audimedia import AudiMediaIE from .audimedia import AudiMediaIE
from .audioboom import AudioBoomIE from .audioboom import AudioBoomIE
from .audiomack import AudiomackIE, AudiomackAlbumIE from .audiomack import AudiomackIE, AudiomackAlbumIE
from .audius import AudiusIE, AudiusPlaylistIE from .audius import (
AudiusIE,
AudiusTrackIE,
AudiusPlaylistIE
)
from .awaan import ( from .awaan import (
AWAANIE, AWAANIE,
AWAANVideoIE, AWAANVideoIE,