mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-01-06 03:20:10 +09:00
Update with traverse_obj()
This commit is contained in:
parent
d699bafdfc
commit
2d7b8c95e3
@ -1,17 +1,13 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
from ..compat import (
|
|
||||||
compat_str,
|
|
||||||
)
|
|
||||||
|
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
strip_or_none,
|
merge_dicts,
|
||||||
try_get,
|
T,
|
||||||
|
traverse_obj,
|
||||||
|
txt_or_none,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,19 +29,23 @@ class BandlabIE(InfoExtractor):
|
|||||||
track_id = self._match_id(url)
|
track_id = self._match_id(url)
|
||||||
config = self._download_json(
|
config = self._download_json(
|
||||||
'http://www.bandlab.com/api/v1.3/posts/%s' % track_id, track_id)
|
'http://www.bandlab.com/api/v1.3/posts/%s' % track_id, track_id)
|
||||||
track_url = config['track']['sample']['audioUrl']
|
track_url = traverse_obj(config, ('track', 'sample', 'audioUrl', T(url_or_none)))
|
||||||
|
if not track_url:
|
||||||
|
raise ExtractorError(
|
||||||
|
'[%s] 'No video formats found!' % (self.ie_key(), ),
|
||||||
|
video_id=track_id, expected=True)
|
||||||
|
title = config['track']['name']
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': track_id,
|
'id': track_id,
|
||||||
'title': config['track']['name'],
|
'title': title,
|
||||||
'url': track_url,
|
'url': track_url,
|
||||||
'artist': config['creator']['name']
|
'artist': traverse_obj(config, ('creator', 'name', T(txt_or_none))),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?bandlab\.com/[^/]+/(?P<kind>albums|collections)/(?P<id>[^/]+)'
|
_VALID_URL = r'https?://(?:www\.)?bandlab\.com/[^/]+/(?P<kind>albums|collections)/(?P<id>[^/]+)'
|
||||||
_TRACK_ID_RE = r'.+/(?P<id>[^/]+)\.m4a'
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'https://www.bandlab.com/sbsdasani/albums/dc26e307-e51f-ed11-95d7-002248452390',
|
'url': 'https://www.bandlab.com/sbsdasani/albums/dc26e307-e51f-ed11-95d7-002248452390',
|
||||||
'playlist': [
|
'playlist': [
|
||||||
@ -137,21 +137,22 @@ class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
resource_id, kind = re.match(self._VALID_URL, url).group('id', 'kind')
|
resource_id, kind = self._match_valid_url(url).group('id', 'kind')
|
||||||
config = self._download_json(
|
config = self._download_json(
|
||||||
'http://www.bandlab.com/api/v1.3/%s/%s' % (kind, resource_id), resource_id)
|
'http://www.bandlab.com/api/v1.3/%s/%s' % (kind, resource_id), resource_id)
|
||||||
entries = []
|
entries = []
|
||||||
for track in try_get(config, lambda x: x['posts'], list) or []:
|
for track in traverse_obj(config, ('posts', Ellipsis)):
|
||||||
url, name = try_get(
|
url, name = (traverse_obj(track, ('track', {
|
||||||
track,
|
'url': ('sample', 'audioUrl', T(url_or_none)
|
||||||
(lambda x: (x['track']['sample']['audioUrl'], x['track']['name']),
|
'name': ('name', T(txt_or_none)),
|
||||||
lambda x: (x['revision']['mixdown']['file'], x['revision']['song']['name'])),
|
}), ('revision', {
|
||||||
tuple) or (None, '', )
|
'url': ('mixdown', 'file', T(url_or_none)),
|
||||||
url = url_or_none(url)
|
'name': ('song', 'name', T(txt_or_none)),
|
||||||
name = strip_or_none(name)
|
})).get(x) for x in ('url', 'name'))
|
||||||
if not (url and name):
|
if not (url and name):
|
||||||
continue
|
continue
|
||||||
track_id = re.match(self._TRACK_ID_RE, url).group('id')
|
track_id = self._search_regex(
|
||||||
|
r'/([^/]+)\.m4a$', url, 'track id', default=None)
|
||||||
if not track_id:
|
if not track_id:
|
||||||
continue
|
continue
|
||||||
entries.append({
|
entries.append({
|
||||||
@ -160,10 +161,9 @@ class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
|||||||
'title': name,
|
'title': name,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return merge_dicts(
|
||||||
'_type': 'playlist',
|
self.playlist_result(entries, playlist_id=resource_id),
|
||||||
'id': resource_id,
|
traverse_obj(config, {
|
||||||
'entries': entries,
|
'album': ('name', T(txt_or_none)),
|
||||||
'album': try_get(config, lambda x: x['name'].strip(), compat_str),
|
'artist': ('creator', 'name', T(txt_or_none)),
|
||||||
'artist': try_get(config, lambda x: x['creator']['name'].strip(), compat_str)
|
}))
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user