]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/bandcamp.py
dcbbdef4346c36c789e49531df1dc602bc35255b
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class BandcampIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://.*?\.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 m_download
= re
.search(r
'freeDownloadPage: "(.*?)"', webpage
)
33 m_trackinfo
= re
.search(r
'trackinfo: (.+),\s*?\n', webpage
)
35 json_code
= m_trackinfo
.group(1)
36 data
= json
.loads(json_code
)[0]
39 for format_id
, format_url
in data
['file'].items():
40 ext
, abr_str
= format_id
.split('-', 1)
42 'format_id': format_id
,
50 self
._sort
_formats
(formats
)
53 'id': compat_str(data
['id']),
54 'title': data
['title'],
56 'duration': float(data
['duration']),
59 raise ExtractorError('No free songs found')
61 download_link
= m_download
.group(1)
63 r
'var TralbumData = {(.*?)id: (?P<id>\d*?)$',
64 webpage
, re
.MULTILINE | re
.DOTALL
).group('id')
66 download_webpage
= self
._download
_webpage
(download_link
, video_id
, 'Downloading free downloads page')
67 # We get the dictionary of the track from some javascript code
68 info
= re
.search(r
'items: (.*?),$', download_webpage
, re
.MULTILINE
).group(1)
69 info
= json
.loads(info
)[0]
70 # We pick mp3-320 for now, until format selection can be easily implemented.
71 mp3_info
= info
['downloads']['mp3-320']
72 # If we try to use this url it says the link has expired
73 initial_url
= mp3_info
['url']
74 re_url
= r
'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$'
75 m_url
= re
.match(re_url
, initial_url
)
76 #We build the url we will use to get the final track url
77 # This url is build in Bandcamp in the script download_bunde_*.js
78 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'))
79 final_url_webpage
= self
._download
_webpage
(request_url
, video_id
, 'Requesting download url')
80 # If we could correctly generate the .rand field the url would be
81 #in the "download_url" key
82 final_url
= re
.search(r
'"retry_url":"(.*?)"', final_url_webpage
).group(1)
86 'title': info
['title'],
90 'thumbnail': info
.get('thumb_url'),
91 'uploader': info
.get('artist'),
95 class BandcampAlbumIE(InfoExtractor
):
96 IE_NAME
= 'Bandcamp:album'
97 _VALID_URL
= r
'https?://(?:(?P<subdomain>[^.]+)\.)?bandcamp\.com(?:/album/(?P<title>[^?#]+))'
100 'url': 'http://blazo.bandcamp.com/album/jazz-format-mixtape-vol-1',
103 'file': '1353101989.mp3',
104 'md5': '39bc1eded3476e927c724321ddf116cf',
110 'file': '38097443.mp3',
111 'md5': '1a2c32e2691474643e912cc6cd4bffaa',
113 'title': 'Kero One - Keep It Alive (Blazo remix)',
120 'skip': 'Bandcamp imposes download limits. See test_playlists:test_bandcamp_album for the playlist test'
123 def _real_extract(self
, url
):
124 mobj
= re
.match(self
._VALID
_URL
, url
)
125 playlist_id
= mobj
.group('subdomain')
126 title
= mobj
.group('title')
127 display_id
= title
or playlist_id
128 webpage
= self
._download
_webpage
(url
, display_id
)
129 tracks_paths
= re
.findall(r
'<a href="(.*?)" itemprop="url">', webpage
)
131 raise ExtractorError('The page doesn\'t contain any tracks')
133 self
.url_result(compat_urlparse
.urljoin(url
, t_path
), ie
=BandcampIE
.ie_key())
134 for t_path
in tracks_paths
]
135 title
= self
._search
_regex
(r
'album_title : "(.*?)"', webpage
, 'title')
139 'display_id': display_id
,