]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bandcamp.py
886b0dfabb7537ebca8a13ce7e4d6d68b9966a4c
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class BandcampIE(InfoExtractor
):
15 _VALID_URL
= r
'http://.*?\.bandcamp\.com/track/(?P<title>.*)'
17 'url': 'http://youtube-dl.bandcamp.com/track/youtube-dl-test-song',
18 'file': '1812978515.mp3',
19 'md5': 'c557841d5e50261777a6585648adf439',
21 "title": "youtube-dl \"'/\\\u00e4\u21ad - youtube-dl test song \"'/\\\u00e4\u21ad",
24 '_skip': 'There is a limit of 200 free downloads / month for the test song'
27 def _real_extract(self
, url
):
28 mobj
= re
.match(self
._VALID
_URL
, url
)
29 title
= mobj
.group('title')
30 webpage
= self
._download
_webpage
(url
, title
)
31 # We get the link to the free download page
32 m_download
= re
.search(r
'freeDownloadPage: "(.*?)"', webpage
)
33 if m_download
is None:
34 m_trackinfo
= re
.search(r
'trackinfo: (.+),\s*?\n', webpage
)
36 json_code
= m_trackinfo
.group(1)
37 data
= json
.loads(json_code
)
40 duration
= int(round(d
['duration']))
42 for format_id
, format_url
in d
['file'].items():
43 ext
, _
, abr_str
= format_id
.partition('-')
46 'format_id': format_id
,
48 'ext': format_id
.partition('-')[0],
50 'acodec': format_id
.partition('-')[0],
51 'abr': int(format_id
.partition('-')[2]),
54 self
._sort
_formats
(formats
)
57 'id': compat_str(d
['id']),
63 raise ExtractorError('No free songs found')
65 download_link
= m_download
.group(1)
67 r
'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
68 webpage
, re
.MULTILINE | re
.DOTALL
).group('id')
70 download_webpage
= self
._download
_webpage
(download_link
, video_id
,
71 'Downloading free downloads page')
72 # We get the dictionary of the track from some javascrip code
73 info
= re
.search(r
'items: (.*?),$',
74 download_webpage
, re
.MULTILINE
).group(1)
75 info
= json
.loads(info
)[0]
76 # We pick mp3-320 for now, until format selection can be easily implemented.
77 mp3_info
= info
['downloads']['mp3-320']
78 # If we try to use this url it says the link has expired
79 initial_url
= mp3_info
['url']
80 re_url
= r
'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
81 m_url
= re
.match(re_url
, initial_url
)
82 #We build the url we will use to get the final track url
83 # This url is build in Bandcamp in the script download_bunde_*.js
84 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'), video_id
, m_url
.group('ts'))
85 final_url_webpage
= self
._download
_webpage
(request_url
, video_id
, 'Requesting download url')
86 # If we could correctly generate the .rand field the url would be
87 #in the "download_url" key
88 final_url
= re
.search(r
'"retry_url":"(.*?)"', final_url_webpage
).group(1)
92 'title': info
['title'],
96 'thumbnail': info
.get('thumb_url'),
97 'uploader': info
.get('artist'),
101 class BandcampAlbumIE(InfoExtractor
):
102 IE_NAME
= 'Bandcamp:album'
103 _VALID_URL
= r
'http://.*?\.bandcamp\.com/album/(?P<title>.*)'
106 'url': 'http://blazo.bandcamp.com/album/jazz-format-mixtape-vol-1',
109 'file': '1353101989.mp3',
110 'md5': '39bc1eded3476e927c724321ddf116cf',
116 'file': '38097443.mp3',
117 'md5': '1a2c32e2691474643e912cc6cd4bffaa',
119 'title': 'Kero One - Keep It Alive (Blazo remix)',
126 'skip': 'Bancamp imposes download limits. See test_playlists:test_bandcamp_album for the playlist test'
129 def _real_extract(self
, url
):
130 mobj
= re
.match(self
._VALID
_URL
, url
)
131 title
= mobj
.group('title')
132 webpage
= self
._download
_webpage
(url
, title
)
133 tracks_paths
= re
.findall(r
'<a href="(.*?)" itemprop="url">', webpage
)
135 raise ExtractorError('The page doesn\'t contain any tracks')
137 self
.url_result(compat_urlparse
.urljoin(url
, t_path
), ie
=BandcampIE
.ie_key())
138 for t_path
in tracks_paths
]
139 title
= self
._search
_regex
(r
'album_title : "(.*?)"', webpage
, 'title')