5 from .common
import InfoExtractor
6 from ..compat
import compat_str
23 class BandcampIE(InfoExtractor
):
24 _VALID_URL
= r
'https?://(?P<uploader>[^/]+)\.bandcamp\.com/track/(?P<id>[^/?#&]+)'
25 _EMBED_REGEX
= [r
'<meta property="og:url"[^>]*?content="(?P<url>.*?bandcamp\.com.*?)"']
27 'url': 'http://youtube-dl.bandcamp.com/track/youtube-dl-test-song',
28 'md5': 'c557841d5e50261777a6585648adf439',
32 'title': "youtube-dl \"'/\\ä↭ - youtube-dl \"'/\\ä↭ - youtube-dl test song \"'/\\ä↭",
34 'uploader': 'youtube-dl "\'/\\ä↭',
35 'upload_date': '20121129',
36 'timestamp': 1354224127,
38 '_skip': 'There is a limit of 200 free downloads / month for the test song'
41 'url': 'http://benprunty.bandcamp.com/track/lanius-battle',
45 'title': 'Ben Prunty - Lanius (Battle)',
46 'thumbnail': r
're:^https?://.*\.jpg$',
47 'uploader': 'Ben Prunty',
48 'timestamp': 1396508491,
49 'upload_date': '20140403',
50 'release_timestamp': 1396483200,
51 'release_date': '20140403',
53 'track': 'Lanius (Battle)',
55 'track_id': '2650410135',
56 'artist': 'Ben Prunty',
57 'album': 'FTL: Advanced Edition Soundtrack',
60 # no free download, mp3 128
61 'url': 'https://relapsealumni.bandcamp.com/track/hail-to-fire',
62 'md5': 'fec12ff55e804bb7f7ebeb77a800c8b7',
66 'title': 'Mastodon - Hail to Fire',
67 'thumbnail': r
're:^https?://.*\.jpg$',
68 'uploader': 'Mastodon',
69 'timestamp': 1322005399,
70 'upload_date': '20111122',
71 'release_timestamp': 1076112000,
72 'release_date': '20040207',
74 'track': 'Hail to Fire',
76 'track_id': '2584466013',
78 'album': 'Call of the Mastodon',
82 def _extract_data_attr(self
, webpage
, video_id
, attr
='tralbum', fatal
=True):
83 return self
._parse
_json
(self
._html
_search
_regex
(
84 r
'data-%s=(["\'])({.+?}
)\
1' % attr, webpage,
85 attr + ' data
', group=2), video_id, fatal=fatal)
87 def _real_extract(self, url):
88 title, uploader = self._match_valid_url(url).group('id', 'uploader
')
89 webpage = self._download_webpage(url, title)
90 tralbum = self._extract_data_attr(webpage, title)
91 thumbnail = self._og_search_thumbnail(webpage)
99 track_info = try_get(tralbum, lambda x: x['trackinfo
'][0], dict)
101 file_ = track_info.get('file')
102 if isinstance(file_, dict):
103 for format_id, format_url in file_.items():
104 if not url_or_none(format_url):
106 ext, abr_str = format_id.split('-', 1)
108 'format_id
': format_id,
109 'url
': self._proto_relative_url(format_url, 'http
:'),
113 'abr
': int_or_none(abr_str),
115 track = track_info.get('title
')
116 track_id = str_or_none(
117 track_info.get('track_id
') or track_info.get('id'))
118 track_number = int_or_none(track_info.get('track_num
'))
119 duration = float_or_none(track_info.get('duration
'))
121 embed = self._extract_data_attr(webpage, title, 'embed
', False)
122 current = tralbum.get('current
') or {}
123 artist = embed.get('artist
') or current.get('artist
') or tralbum.get('artist
')
124 timestamp = unified_timestamp(
125 current.get('publish_date
') or tralbum.get('album_publish_date
'))
127 download_link = tralbum.get('freeDownloadPage
')
129 track_id = compat_str(tralbum['id'])
131 download_webpage = self._download_webpage(
132 download_link, track_id, 'Downloading free downloads page
')
134 blob = self._extract_data_attr(download_webpage, track_id, 'blob
')
137 blob, (lambda x: x['digital_items
'][0],
138 lambda x: x['download_items
'][0]), dict)
140 downloads = info.get('downloads
')
141 if isinstance(downloads, dict):
143 track = info.get('title
')
145 artist = info.get('artist
')
147 thumbnail = info.get('thumb_url
')
149 download_formats = {}
150 download_formats_list = blob.get('download_formats
')
151 if isinstance(download_formats_list, list):
152 for f in blob['download_formats
']:
153 name, ext = f.get('name
'), f.get('file_extension
')
154 if all(isinstance(x, compat_str) for x in (name, ext)):
155 download_formats[name] = ext.strip('.')
157 for format_id, f in downloads.items():
158 format_url = f.get('url
')
161 # Stat URL generation algorithm is reverse engineered from
162 # download_*_bundle_*.js
163 stat_url = update_url_query(
164 format_url.replace('/download
/', '/statdownload
/'), {
165 '.rand
': int(time.time() * 1000 * random.random()),
167 format_id = f.get('encoding_name
') or format_id
168 stat = self._download_json(
169 stat_url, track_id, 'Downloading
%s JSON
' % format_id,
170 transform_source=lambda s: s[s.index('{'):s.rindex('}
') + 1],
174 retry_url = url_or_none(stat.get('retry_url
'))
178 'url
': self._proto_relative_url(retry_url, 'http
:'),
179 'ext
': download_formats.get(format_id),
180 'format_id
': format_id,
181 'format_note
': f.get('description
'),
182 'filesize
': parse_filesize(f.get('size_mb
')),
184 'acodec
': format_id.split('-')[0],
187 title = '%s - %s' % (artist, track) if artist else track
190 duration = float_or_none(self._html_search_meta(
191 'duration
', webpage, default=None))
196 'thumbnail
': thumbnail,
198 'uploader_id
': uploader,
199 'uploader_url
': f'https
://{uploader}
.bandcamp
.com
',
200 'timestamp
': timestamp,
201 'release_timestamp
': unified_timestamp(tralbum.get('album_release_date
')),
202 'duration
': duration,
204 'track_number
': track_number,
205 'track_id
': track_id,
207 'album
': embed.get('album_title
'),
212 class BandcampAlbumIE(BandcampIE): # XXX: Do not subclass from concrete IE
213 IE_NAME = 'Bandcamp
:album
'
214 _VALID_URL = r'https?
://(?
:(?P
<subdomain
>[^
.]+)\
.)?bandcamp\
.com
/album
/(?P
<id>[^
/?
#&]+)'
217 'url': 'http://blazo.bandcamp.com/album/jazz-format-mixtape-vol-1',
220 'md5': '39bc1eded3476e927c724321ddf116cf',
224 'title': 'Blazo - Intro',
225 'timestamp': 1311756226,
226 'upload_date': '20110727',
231 'md5': '1a2c32e2691474643e912cc6cd4bffaa',
235 'title': 'Blazo - Kero One - Keep It Alive (Blazo remix)',
236 'timestamp': 1311757238,
237 'upload_date': '20110727',
243 'title': 'Jazz Format Mixtape vol.1',
244 'id': 'jazz-format-mixtape-vol-1',
245 'uploader_id': 'blazo',
250 'skip': 'Bandcamp imposes download limits.'
252 'url': 'http://nightbringer.bandcamp.com/album/hierophany-of-the-open-grave',
254 'title': 'Hierophany of the Open Grave',
255 'uploader_id': 'nightbringer',
256 'id': 'hierophany-of-the-open-grave',
258 'playlist_mincount': 9,
260 # with escaped quote in title
261 'url': 'https://jstrecords.bandcamp.com/album/entropy-ep',
263 'title': '"Entropy" EP',
264 'uploader_id': 'jstrecords',
266 'description': 'md5:0ff22959c943622972596062f2f366a5',
268 'playlist_mincount': 3,
270 # not all tracks have songs
271 'url': 'https://insulters.bandcamp.com/album/we-are-the-plague',
273 'id': 'we-are-the-plague',
274 'title': 'WE ARE THE PLAGUE',
275 'uploader_id': 'insulters',
276 'description': 'md5:b3cf845ee41b2b1141dc7bde9237255f',
282 def suitable(cls
, url
):
284 if BandcampWeeklyIE
.suitable(url
) or BandcampIE
.suitable(url
)
285 else super(BandcampAlbumIE
, cls
).suitable(url
))
287 def _real_extract(self
, url
):
288 uploader_id
, album_id
= self
._match
_valid
_url
(url
).groups()
289 playlist_id
= album_id
or uploader_id
290 webpage
= self
._download
_webpage
(url
, playlist_id
)
291 tralbum
= self
._extract
_data
_attr
(webpage
, playlist_id
)
292 track_info
= tralbum
.get('trackinfo')
294 raise ExtractorError('The page doesn\'t contain any tracks')
295 # Only tracks with duration info have songs
298 urljoin(url
, t
['title_link']), BandcampIE
.ie_key(),
299 str_or_none(t
.get('track_id') or t
.get('id')), t
.get('title'))
301 if t
.get('duration')]
303 current
= tralbum
.get('current') or {}
307 'uploader_id': uploader_id
,
309 'title': current
.get('title'),
310 'description': current
.get('about'),
315 class BandcampWeeklyIE(BandcampIE
): # XXX: Do not subclass from concrete IE
316 IE_NAME
= 'Bandcamp:weekly'
317 _VALID_URL
= r
'https?://(?:www\.)?bandcamp\.com/?\?(?:.*?&)?show=(?P<id>\d+)'
319 'url': 'https://bandcamp.com/?show=224',
320 'md5': 'b00df799c733cf7e0c567ed187dea0fd',
324 'title': 'BC Weekly April 4th 2017 - Magic Moments',
325 'description': 'md5:5d48150916e8e02d030623a48512c874',
327 'release_date': '20170404',
328 'series': 'Bandcamp Weekly',
329 'episode': 'Magic Moments',
336 'url': 'https://bandcamp.com/?blah/blah@&show=228',
337 'only_matching': True
340 def _real_extract(self
, url
):
341 show_id
= self
._match
_id
(url
)
342 webpage
= self
._download
_webpage
(url
, show_id
)
344 blob
= self
._extract
_data
_attr
(webpage
, show_id
, 'blob')
346 show
= blob
['bcw_data'][show_id
]
349 for format_id
, format_url
in show
['audio_stream'].items():
350 if not url_or_none(format_url
):
352 for known_ext
in KNOWN_EXTENSIONS
:
353 if known_ext
in format_id
:
359 'format_id': format_id
,
365 title
= show
.get('audio_title') or 'Bandcamp Weekly'
366 subtitle
= show
.get('subtitle')
368 title
+= ' - %s' % subtitle
373 'description': show
.get('desc') or show
.get('short_desc'),
374 'duration': float_or_none(show
.get('audio_duration')),
376 'release_date': unified_strdate(show
.get('published_date')),
377 'series': 'Bandcamp Weekly',
378 'episode': show
.get('subtitle'),
379 'episode_id': show_id
,
384 class BandcampUserIE(InfoExtractor
):
385 IE_NAME
= 'Bandcamp:user'
386 _VALID_URL
= r
'https?://(?!www\.)(?P<id>[^.]+)\.bandcamp\.com(?:/music)?/?(?:[#?]|$)'
389 # Type 1 Bandcamp user page.
390 'url': 'https://adrianvonziegler.bandcamp.com',
392 'id': 'adrianvonziegler',
393 'title': 'Discography of adrianvonziegler',
395 'playlist_mincount': 23,
397 # Bandcamp user page with only one album
398 'url': 'http://dotscale.bandcamp.com',
401 'title': 'Discography of dotscale'
405 # Type 2 Bandcamp user page.
406 'url': 'https://nightcallofficial.bandcamp.com',
408 'id': 'nightcallofficial',
409 'title': 'Discography of nightcallofficial',
413 'url': 'https://steviasphere.bandcamp.com/music',
414 'playlist_mincount': 47,
416 'id': 'steviasphere',
417 'title': 'Discography of steviasphere',
420 'url': 'https://coldworldofficial.bandcamp.com/music',
421 'playlist_mincount': 10,
423 'id': 'coldworldofficial',
424 'title': 'Discography of coldworldofficial',
427 'url': 'https://nuclearwarnowproductions.bandcamp.com/music',
428 'playlist_mincount': 399,
430 'id': 'nuclearwarnowproductions',
431 'title': 'Discography of nuclearwarnowproductions',
435 def _real_extract(self
, url
):
436 uploader
= self
._match
_id
(url
)
437 webpage
= self
._download
_webpage
(url
, uploader
)
439 discography_data
= (re
.findall(r
'<li data-item-id=["\'][^
>]+>\s
*<a href
=["\'](?![^"\'/]*?
/merch
)([^
"\']+)', webpage)
440 or re.findall(r'<div[^>]+trackTitle["\'][^
"\']+["\']([^
"\']+)', webpage))
442 return self.playlist_from_matches(
443 discography_data, uploader, f'Discography of {uploader}', getter=lambda x: urljoin(url, x))