mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 22:37:35 +00:00
use try_get in bandlab extractor
This commit is contained in:
parent
06400d1d0f
commit
c673485d4e
@ -5,6 +5,16 @@ import re
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
|
||||||
|
from ..compat import (
|
||||||
|
compat_str,
|
||||||
|
)
|
||||||
|
|
||||||
|
from ..utils import (
|
||||||
|
strip_or_none,
|
||||||
|
try_get,
|
||||||
|
url_or_none,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class BandlabIE(InfoExtractor):
|
class BandlabIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?bandlab\.com/post/(?P<id>[^/]+)'
|
_VALID_URL = r'https?://(?:www\.)?bandlab\.com/post/(?P<id>[^/]+)'
|
||||||
@ -133,17 +143,20 @@ class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
|||||||
kind = kind_regex.match(url).group('kind')
|
kind = kind_regex.match(url).group('kind')
|
||||||
config = self._download_json(
|
config = self._download_json(
|
||||||
'http://www.bandlab.com/api/v1.3/%s/%s' % kind, resource_id)
|
'http://www.bandlab.com/api/v1.3/%s/%s' % kind, resource_id)
|
||||||
tracks = config['posts']
|
|
||||||
entries = []
|
entries = []
|
||||||
for track in config['posts']:
|
for track in try_get(config, lambda x: x['posts'], list) or []:
|
||||||
if 'track' in track:
|
url, name = try_get(
|
||||||
url = track['track']['sample']['audioUrl']
|
track,
|
||||||
name = track['track']['name']
|
(lambda x: (x['track']['sample']['audioUrl'], x['track']['name']),
|
||||||
elif 'revision' in track:
|
lambda x: (x['revision']['mixdown']['file'], x['revision']['song']['name'])),
|
||||||
url = track['revision']['mixdown']['file']
|
tuple) or (None, '', )
|
||||||
name = track['revision']['song']['name']
|
url = url_or_none(url)
|
||||||
else:
|
name = strip_or_none(name)
|
||||||
raise Exception("Neither track nor revision found in 'posts' object")
|
if not (url and name):
|
||||||
|
continue
|
||||||
|
id = self._TRACK_ID_RE.match(url).groupdict().get('id')
|
||||||
|
if not id:
|
||||||
|
continue
|
||||||
entries.append({
|
entries.append({
|
||||||
'url': url,
|
'url': url,
|
||||||
'id': self._TRACK_URL_RE.match(url).group('id'),
|
'id': self._TRACK_URL_RE.match(url).group('id'),
|
||||||
@ -154,6 +167,6 @@ class BandlabAlbumOrPlaylistIE(InfoExtractor):
|
|||||||
'_type': 'playlist',
|
'_type': 'playlist',
|
||||||
'id': resource_id,
|
'id': resource_id,
|
||||||
'entries': entries,
|
'entries': entries,
|
||||||
'album': config['name'],
|
'album': try_get(config, lambda x: x['name'].strip(), compat_str),
|
||||||
'artist': config['creator']['name']
|
'artist': try_get(config, lambda x: x['creator']['name'].strip(), compat_str)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user