]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bandcamp.py
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
16 class BandcampIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://.*?\.bandcamp\.com/track/(?P<title>.*)'
19 'url': 'http://youtube-dl.bandcamp.com/track/youtube-dl-test-song',
20 'md5': 'c557841d5e50261777a6585648adf439',
24 'title': "youtube-dl \"'/\\\u00e4\u21ad - youtube-dl test song \"'/\\\u00e4\u21ad",
27 '_skip': 'There is a limit of 200 free downloads / month for the test song'
29 'url': 'http://benprunty.bandcamp.com/track/lanius-battle',
30 'md5': '2b68e5851514c20efdff2afc5603b8b4',
34 'title': 'Lanius (Battle)',
35 'uploader': 'Ben Prunty Music',
39 def _real_extract(self
, url
):
40 mobj
= re
.match(self
._VALID
_URL
, url
)
41 title
= mobj
.group('title')
42 webpage
= self
._download
_webpage
(url
, title
)
43 m_download
= re
.search(r
'freeDownloadPage: "(.*?)"', webpage
)
45 m_trackinfo
= re
.search(r
'trackinfo: (.+),\s*?\n', webpage
)
47 json_code
= m_trackinfo
.group(1)
48 data
= json
.loads(json_code
)[0]
51 for format_id
, format_url
in data
['file'].items():
52 ext
, abr_str
= format_id
.split('-', 1)
54 'format_id': format_id
,
62 self
._sort
_formats
(formats
)
65 'id': compat_str(data
['id']),
66 'title': data
['title'],
68 'duration': float(data
['duration']),
71 raise ExtractorError('No free songs found')
73 download_link
= m_download
.group(1)
74 video_id
= self
._search
_regex
(
75 r
'(?ms)var TralbumData = .*?[{,]\s*id: (?P<id>\d+),?$',
78 download_webpage
= self
._download
_webpage
(download_link
, video_id
, 'Downloading free downloads page')
79 # We get the dictionary of the track from some javascript code
80 all_info
= self
._parse
_json
(self
._search
_regex
(
81 r
'(?sm)items: (.*?),$', download_webpage
, 'items'), video_id
)
83 # We pick mp3-320 for now, until format selection can be easily implemented.
84 mp3_info
= info
['downloads']['mp3-320']
85 # If we try to use this url it says the link has expired
86 initial_url
= mp3_info
['url']
88 r
'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$',
90 # We build the url we will use to get the final track url
91 # This url is build in Bandcamp in the script download_bunde_*.js
92 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'))
93 final_url_webpage
= self
._download
_webpage
(request_url
, video_id
, 'Requesting download url')
94 # If we could correctly generate the .rand field the url would be
95 # in the "download_url" key
96 final_url
= self
._search
_regex
(
97 r
'"retry_url":"(.*?)"', final_url_webpage
, 'final video URL')
101 'title': info
['title'],
105 'thumbnail': info
.get('thumb_url'),
106 'uploader': info
.get('artist'),
110 class BandcampAlbumIE(InfoExtractor
):
111 IE_NAME
= 'Bandcamp:album'
112 _VALID_URL
= r
'https?://(?:(?P<subdomain>[^.]+)\.)?bandcamp\.com(?:/album/(?P<album_id>[^?#]+)|/?(?:$|[?#]))'
115 'url': 'http://blazo.bandcamp.com/album/jazz-format-mixtape-vol-1',
118 'md5': '39bc1eded3476e927c724321ddf116cf',
126 'md5': '1a2c32e2691474643e912cc6cd4bffaa',
130 'title': 'Kero One - Keep It Alive (Blazo remix)',
135 'title': 'Jazz Format Mixtape vol.1',
136 'id': 'jazz-format-mixtape-vol-1',
137 'uploader_id': 'blazo',
142 'skip': 'Bandcamp imposes download limits.'
144 'url': 'http://nightbringer.bandcamp.com/album/hierophany-of-the-open-grave',
146 'title': 'Hierophany of the Open Grave',
147 'uploader_id': 'nightbringer',
148 'id': 'hierophany-of-the-open-grave',
150 'playlist_mincount': 9,
152 'url': 'http://dotscale.bandcamp.com',
156 'uploader_id': 'dotscale',
158 'playlist_mincount': 7,
161 def _real_extract(self
, url
):
162 mobj
= re
.match(self
._VALID
_URL
, url
)
163 uploader_id
= mobj
.group('subdomain')
164 album_id
= mobj
.group('album_id')
165 playlist_id
= album_id
or uploader_id
166 webpage
= self
._download
_webpage
(url
, playlist_id
)
167 tracks_paths
= re
.findall(r
'<a href="(.*?)" itemprop="url">', webpage
)
169 raise ExtractorError('The page doesn\'t contain any tracks')
171 self
.url_result(compat_urlparse
.urljoin(url
, t_path
), ie
=BandcampIE
.ie_key())
172 for t_path
in tracks_paths
]
173 title
= self
._search
_regex
(
174 r
'album_title\s*:\s*"(.*?)"', webpage
, 'title', fatal
=False)
177 'uploader_id': uploader_id
,