1 from .common
import InfoExtractor
12 from ..utils
.traversal
import traverse_obj
, value
15 class BandlabBaseIE(InfoExtractor
):
16 def _call_api(self
, endpoint
, asset_id
, **kwargs
):
17 headers
= kwargs
.pop('headers', None) or {}
18 return self
._download
_json
(
19 f
'https://www.bandlab.com/api/v1.3/{endpoint}/{asset_id}',
21 'accept': 'application/json',
22 'referer': 'https://www.bandlab.com/',
23 'x-client-id': 'BandLab-Web',
24 'x-client-version': '10.1.124',
28 def _parse_revision(self
, revision_data
, url
=None):
31 'media_type': 'revision',
32 'extractor_key': BandlabIE
.ie_key(),
33 'extractor': BandlabIE
.IE_NAME
,
34 **traverse_obj(revision_data
, {
36 'id', ({value(url
)}, {format_field(template
='https://www.bandlab.com/revision/%s')}), filter, any
),
37 'id': (('revisionId', 'id'), {str}
, any
),
38 'title': ('song', 'name', {str}
),
39 'track': ('song', 'name', {str}
),
40 'url': ('mixdown', 'file', {url_or_none}
),
41 'thumbnail': ('song', 'picture', 'url', {url_or_none}
),
42 'description': ('description', {str}
),
43 'uploader': ('creator', 'name', {str}
),
44 'uploader_id': ('creator', 'username', {str}
),
45 'timestamp': ('createdOn', {parse_iso8601}
),
46 'duration': ('mixdown', 'duration', {float_or_none}
),
47 'view_count': ('counters', 'plays', {int_or_none}
),
48 'like_count': ('counters', 'likes', {int_or_none}
),
49 'comment_count': ('counters', 'comments', {int_or_none}
),
50 'genres': ('genres', ..., 'name', {str}
),
54 def _parse_track(self
, track_data
, url
=None):
57 'media_type': 'track',
58 'extractor_key': BandlabIE
.ie_key(),
59 'extractor': BandlabIE
.IE_NAME
,
60 **traverse_obj(track_data
, {
62 'id', ({value(url
)}, {format_field(template
='https://www.bandlab.com/post/%s')}), filter, any
),
63 'id': (('revisionId', 'id'), {str}
, any
),
64 'url': ('track', 'sample', 'audioUrl', {url_or_none}
),
65 'title': ('track', 'name', {str}
),
66 'track': ('track', 'name', {str}
),
67 'description': ('caption', {str}
),
68 'thumbnail': ('track', 'picture', ('original', 'url'), {url_or_none}
, any
),
69 'view_count': ('counters', 'plays', {int_or_none}
),
70 'like_count': ('counters', 'likes', {int_or_none}
),
71 'comment_count': ('counters', 'comments', {int_or_none}
),
72 'duration': ('track', 'sample', 'duration', {float_or_none}
),
73 'uploader': ('creator', 'name', {str}
),
74 'uploader_id': ('creator', 'username', {str}
),
75 'timestamp': ('createdOn', {parse_iso8601}
),
79 def _parse_video(self
, video_data
, url
=None):
81 'media_type': 'video',
82 'extractor_key': BandlabIE
.ie_key(),
83 'extractor': BandlabIE
.IE_NAME
,
84 **traverse_obj(video_data
, {
87 'id', ({value(url
)}, {format_field(template
='https://www.bandlab.com/post/%s')}), filter, any
),
88 'url': ('video', 'url', {url_or_none}
),
89 'title': ('caption', {lambda x
: x
.replace('\n', ' ')}, {truncate_string(left
=50)}),
90 'description': ('caption', {str}
),
91 'thumbnail': ('video', 'picture', 'url', {url_or_none}
),
92 'view_count': ('video', 'counters', 'plays', {int_or_none}
),
93 'like_count': ('video', 'counters', 'likes', {int_or_none}
),
94 'comment_count': ('counters', 'comments', {int_or_none}
),
95 'duration': ('video', 'duration', {float_or_none}
),
96 'uploader': ('creator', 'name', {str}
),
97 'uploader_id': ('creator', 'username', {str}
),
102 class BandlabIE(BandlabBaseIE
):
104 r
'https?://(?:www\.)?bandlab.com/(?P<url_type>track|post|revision)/(?P<id>[\da-f_-]+)',
105 r
'https?://(?:www\.)?bandlab.com/(?P<url_type>embed)/\?(?:[^#]*&)?id=(?P<id>[\da-f-]+)',
107 _EMBED_REGEX
= [rf
'<iframe[^>]+src=[\'"](?P<url>{_VALID_URL[1]})[\'"]']
109 'url': 'https://www.bandlab.com/track/04b37e88dba24967b9dac8eb8567ff39_07d7f906fc96ee11b75e000d3a428fff',
110 'md5': '46f7b43367dd268bbcf0bbe466753b2c',
112 'id': '02d7f906-fc96-ee11-b75e-000d3a428fff',
114 'uploader_id': 'ender_milze',
115 'track': 'sweet black',
116 'description': 'composed by juanjn3737',
117 'timestamp': 1702171963,
120 'duration': 54.629999999999995,
121 'title': 'sweet black',
122 'upload_date': '20231210',
123 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/songs/fa082beb-b856-4730-9170-a57e4e32cc2c/',
125 'uploader': 'ender milze',
126 'comment_count': int,
127 'media_type': 'revision',
130 # Same track as above but post URL
131 'url': 'https://www.bandlab.com/post/07d7f906-fc96-ee11-b75e-000d3a428fff',
132 'md5': '46f7b43367dd268bbcf0bbe466753b2c',
134 'id': '02d7f906-fc96-ee11-b75e-000d3a428fff',
136 'uploader_id': 'ender_milze',
137 'track': 'sweet black',
138 'description': 'composed by juanjn3737',
139 'timestamp': 1702171973,
142 'duration': 54.629999999999995,
143 'title': 'sweet black',
144 'upload_date': '20231210',
145 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/songs/fa082beb-b856-4730-9170-a57e4e32cc2c/',
147 'uploader': 'ender milze',
148 'comment_count': int,
149 'media_type': 'revision',
153 'url': 'https://www.bandlab.com/track/048916c2-c6da-ee11-85f9-6045bd2e11f9?sharedKey=0NNWX8qYAEmI38lWAzCNDA',
154 'md5': '15174b57c44440e2a2008be9cae00250',
156 'id': '038916c2-c6da-ee11-85f9-6045bd2e11f9',
158 'comment_count': int,
160 'uploader_id': 'user8353034818103753',
161 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/songs/51b18363-da23-4b9b-a29c-2933a3e561ca/',
162 'timestamp': 1709625771,
163 'track': 'PodcastMaerchen4b',
166 'description': 'Podcast: Neues aus der Märchenwelt',
168 'upload_date': '20240305',
169 'uploader': 'Erna Wageneder',
170 'title': 'PodcastMaerchen4b',
171 'media_type': 'revision',
174 # Different Revision selected
175 'url': 'https://www.bandlab.com/track/130343fc-148b-ea11-96d2-0003ffd1fc09?revId=110343fc-148b-ea11-96d2-0003ffd1fc09',
176 'md5': '74e055ef9325d63f37088772fbfe4454',
178 'id': '110343fc-148b-ea11-96d2-0003ffd1fc09',
180 'timestamp': 1588273294,
181 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/users/b612e533-e4f7-4542-9f50-3fcfd8dd822c/',
182 'description': 'Final Revision.',
183 'title': 'Replay ( Instrumental)',
184 'uploader': 'David R Sparks',
185 'uploader_id': 'davesnothome69',
187 'comment_count': int,
188 'track': 'Replay ( Instrumental)',
190 'upload_date': '20200430',
193 'media_type': 'revision',
197 'url': 'https://www.bandlab.com/post/5cdf9036-3857-ef11-991a-6045bd36e0d9',
198 'md5': '8caa2ef28e86c1dacf167293cfdbeba9',
200 'id': '5cdf9036-3857-ef11-991a-6045bd36e0d9',
203 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/videos/67c6cef1-cef6-40d3-831e-a55bc1dcb972/',
204 'comment_count': int,
205 'title': 'backing vocals',
206 'uploader_id': 'marliashya',
209 'description': 'backing vocals',
210 'media_type': 'video',
214 'url': 'https://www.bandlab.com/embed/?blur=false&id=014de0a4-7d82-ea11-a94c-0003ffd19c0f',
215 'md5': 'a4ad05cb68c54faaed9b0a8453a8cf4a',
217 'id': '014de0a4-7d82-ea11-a94c-0003ffd19c0f',
219 'comment_count': int,
220 'genres': ['Electronic'],
221 'uploader': 'Charlie Henson',
222 'timestamp': 1587328674,
223 'upload_date': '20200419',
225 'track': 'Positronic Meltdown',
227 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/songs/87165bc3-5439-496e-b1f7-a9f13b541ff2/',
228 'description': 'Checkout my tracks at AOMX http://aomxsounds.com/',
229 'uploader_id': 'microfreaks',
230 'title': 'Positronic Meltdown',
232 'media_type': 'revision',
235 # Track without revisions available
236 'url': 'https://www.bandlab.com/track/55767ac51789ea11a94c0003ffd1fc09_2f007b0a37b94ec7a69bc25ae15108a5',
237 'md5': 'f05d68a3769952c2d9257c473e14c15f',
239 'id': '55767ac51789ea11a94c0003ffd1fc09_2f007b0a37b94ec7a69bc25ae15108a5',
246 'comment_count': int,
247 'uploader': 'Sorakime',
248 'uploader_id': 'sorakime',
249 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/users/572a351a-0f3a-4c6a-ac39-1a5defdeeb1c/',
250 'timestamp': 1691162128,
251 'upload_date': '20230804',
252 'media_type': 'track',
255 'url': 'https://www.bandlab.com/revision/014de0a4-7d82-ea11-a94c-0003ffd19c0f',
256 'only_matching': True,
259 'url': 'https://phantomluigi.github.io/',
261 'id': 'e14223c3-7871-ef11-bdfd-000d3a980db3',
264 'upload_date': '20240913',
265 'uploader_id': 'phantommusicofficial',
266 'timestamp': 1726194897,
267 'uploader': 'Phantom',
268 'comment_count': int,
269 'genres': ['Progresive Rock'],
270 'description': 'md5:a38cd668f7a2843295ef284114f18429',
273 'title': 'Vermilion Pt. 2 (Cover)',
274 'track': 'Vermilion Pt. 2 (Cover)',
275 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/songs/62b10750-7aef-4f42-ad08-1af52f577e97/',
276 'media_type': 'revision',
280 def _real_extract(self
, url
):
281 display_id
, url_type
= self
._match
_valid
_url
(url
).group('id', 'url_type')
284 revision_id
= traverse_obj(qs
, (('revId', 'id'), 0, any
))
285 if url_type
== 'revision':
286 revision_id
= display_id
290 post_data
= self
._call
_api
(
291 'posts', display_id
, note
='Downloading post data',
292 query
=traverse_obj(qs
, {'sharedKey': ('sharedKey', 0)}))
294 revision_id
= traverse_obj(post_data
, (('revisionId', ('revision', 'id')), {str}
, any
))
295 revision_data
= traverse_obj(post_data
, ('revision', {dict}
))
297 if not revision_data
and not revision_id
:
298 post_type
= post_data
.get('type')
299 if post_type
== 'Video':
300 return self
._parse
_video
(post_data
, url
=url
)
301 if post_type
== 'Track':
302 return self
._parse
_track
(post_data
, url
=url
)
303 raise ExtractorError(f
'Could not extract data for post type {post_type!r}')
305 if not revision_data
:
306 revision_data
= self
._call
_api
(
307 'revisions', revision_id
, note
='Downloading revision data', query
={'edit': 'false'})
309 return self
._parse
_revision
(revision_data
, url
=url
)
312 class BandlabPlaylistIE(BandlabBaseIE
):
314 r
'https?://(?:www\.)?bandlab.com/(?:[\w]+/)?(?P<type>albums|collections)/(?P<id>[\da-f-]+)',
315 r
'https?://(?:www\.)?bandlab.com/(?P<type>embed)/collection/\?(?:[^#]*&)?id=(?P<id>[\da-f-]+)',
317 _EMBED_REGEX
= [rf
'<iframe[^>]+src=[\'"](?P<url>{_VALID_URL[1]})[\'"]']
319 'url': 'https://www.bandlab.com/davesnothome69/albums/89b79ea6-de42-ed11-b495-00224845aac7',
321 'thumbnail': 'https://bl-prod-images.azureedge.net/v1.3/albums/69507ff3-579a-45be-afca-9e87eddec944/',
322 'release_date': '20221003',
327 'description': 'A collection of some feel good, rock hits.',
328 'comment_count': int,
330 'id': '89b79ea6-de42-ed11-b495-00224845aac7',
331 'uploader': 'David R Sparks',
332 'uploader_id': 'davesnothome69',
334 'playlist_count': 10,
336 'url': 'https://www.bandlab.com/slytheband/collections/955102d4-1040-ef11-86c3-000d3a42581b',
338 'id': '955102d4-1040-ef11-86c3-000d3a42581b',
339 'timestamp': 1720762659,
341 'title': 'My Shit 🖤',
342 'uploader_id': 'slytheband',
344 'upload_date': '20240712',
346 'thumbnail': 'https://bandlabimages.azureedge.net/v1.0/collections/2c64ca12-b180-4b76-8587-7a8da76bddc8/',
348 'playlist_count': 15,
350 # Embeds can contain both albums and collections with the same URL pattern. This is an album
351 'url': 'https://www.bandlab.com/embed/collection/?id=12cc6f7f-951b-ee11-907c-00224844f303',
353 'id': '12cc6f7f-951b-ee11-907c-00224844f303',
354 'release_date': '20230706',
355 'description': 'This is a collection of songs I created when I had an Amiga computer.',
357 'title': 'Mark Salud The Amiga Collection',
358 'uploader_id': 'mssirmooth1962',
359 'comment_count': int,
360 'thumbnail': 'https://bl-prod-images.azureedge.net/v1.3/albums/d618bd7b-0537-40d5-bdd8-61b066e77d59/',
362 'uploader': 'Mark Salud',
363 'album': 'Mark Salud The Amiga Collection',
366 'playlist_count': 24,
368 # Tracks without revision id
369 'url': 'https://www.bandlab.com/embed/collection/?id=e98aafb5-d932-ee11-b8f0-00224844c719',
372 'uploader_id': 'sorakime',
373 'comment_count': int,
374 'uploader': 'Sorakime',
376 'description': 'md5:4ec31c568a5f5a5a2b17572ea64c3825',
377 'release_date': '20230812',
380 'album_type': 'Album',
381 'id': 'e98aafb5-d932-ee11-b8f0-00224844c719',
382 'thumbnail': 'https://bl-prod-images.azureedge.net/v1.3/albums/20c890de-e94a-4422-828a-2da6377a13c8/',
384 'playlist_count': 13,
386 'url': 'https://www.bandlab.com/albums/89b79ea6-de42-ed11-b495-00224845aac7',
387 'only_matching': True,
390 def _entries(self
, album_data
):
391 for post
in traverse_obj(album_data
, ('posts', lambda _
, v
: v
['type'])):
392 post_type
= post
['type']
393 if post_type
== 'Revision':
394 yield self
._parse
_revision
(post
.get('revision'))
395 elif post_type
== 'Track':
396 yield self
._parse
_track
(post
)
397 elif post_type
== 'Video':
398 yield self
._parse
_video
(post
)
400 self
.report_warning(f
'Skipping unknown post type: "{post_type}"')
402 def _real_extract(self
, url
):
403 playlist_id
, playlist_type
= self
._match
_valid
_url
(url
).group('id', 'type')
406 'albums': ['albums'],
407 'collections': ['collections'],
408 'embed': ['collections', 'albums'],
410 for endpoint
in endpoints
:
411 playlist_data
= self
._call
_api
(
412 endpoint
, playlist_id
, note
=f
'Downloading {endpoint[:-1]} data',
413 fatal
=False, expected_status
=404)
414 if not playlist_data
.get('errorCode'):
415 playlist_type
= endpoint
417 if error_code
:= playlist_data
.get('errorCode'):
418 raise ExtractorError(f
'Could not find playlist data. Error code: "{error_code}"')
420 return self
.playlist_result(
421 self
._entries
(playlist_data
), playlist_id
,
422 **traverse_obj(playlist_data
, {
423 'title': ('name', {str}
),
424 'description': ('description', {str}
),
425 'uploader': ('creator', 'name', {str}
),
426 'uploader_id': ('creator', 'username', {str}
),
427 'timestamp': ('createdOn', {parse_iso8601}
),
428 'release_date': ('releaseDate', {lambda x
: x
.replace('-', '')}, filter),
429 'thumbnail': ('picture', ('original', 'url'), {url_or_none}
, any
),
430 'like_count': ('counters', 'likes', {int_or_none}
),
431 'comment_count': ('counters', 'comments', {int_or_none}
),
432 'view_count': ('counters', 'plays', {int_or_none}
),
434 **(traverse_obj(playlist_data
, {
435 'album': ('name', {str}
),
436 'album_type': ('type', {str}
),
437 }) if playlist_type
== 'albums' else {}))