]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bandcamp.py
4 from .common
import InfoExtractor
10 class BandcampIE(InfoExtractor
):
11 _VALID_URL
= r
'http://.*?\.bandcamp\.com/track/(?P<title>.*)'
13 def _real_extract(self
, url
):
14 mobj
= re
.match(self
._VALID
_URL
, url
)
15 title
= mobj
.group('title')
16 webpage
= self
._download
_webpage
(url
, title
)
17 # We get the link to the free download page
18 m_download
= re
.search(r
'freeDownloadPage: "(.*?)"', webpage
)
19 if m_download
is None:
20 raise ExtractorError(u
'No free songs found')
22 download_link
= m_download
.group(1)
23 id = re
.search(r
'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
24 webpage
, re
.MULTILINE|re
.DOTALL
).group('id')
26 download_webpage
= self
._download
_webpage
(download_link
, id,
27 'Downloading free downloads page')
28 # We get the dictionary of the track from some javascrip code
29 info
= re
.search(r
'items: (.*?),$',
30 download_webpage
, re
.MULTILINE
).group(1)
31 info
= json
.loads(info
)[0]
32 # We pick mp3-320 for now, until format selection can be easily implemented.
33 mp3_info
= info
[u
'downloads'][u
'mp3-320']
34 # If we try to use this url it says the link has expired
35 initial_url
= mp3_info
[u
'url']
36 re_url
= r
'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
37 m_url
= re
.match(re_url
, initial_url
)
38 #We build the url we will use to get the final track url
39 # This url is build in Bandcamp in the script download_bunde_*.js
40 request_url
= '%s/statdownload/track?enc=mp3-320&fsig=%s&id=%s&ts=%s&.rand=665028774616&.vrs=1' % (m_url
.group('server'), m_url
.group('fsig'), id, m_url
.group('ts'))
41 final_url_webpage
= self
._download
_webpage
(request_url
, id, 'Requesting download url')
42 # If we could correctly generate the .rand field the url would be
43 #in the "download_url" key
44 final_url
= re
.search(r
'"retry_url":"(.*?)"', final_url_webpage
).group(1)
46 track_info
= {'id':id,
47 'title' : info
[u
'title'],
50 'thumbnail' : info
[u
'thumb_url'],
51 'uploader' : info
[u
'artist']