]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hypem.py
1 from __future__
import unicode_literals
7 from .common
import InfoExtractor
10 compat_urllib_request
,
16 class HypemIE(InfoExtractor
):
17 _VALID_URL
= r
'http://(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
19 'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME',
20 'md5': 'b9cc91b5af8995e9f0c1cee04c575828',
25 'uploader': 'BODYWORK',
29 def _real_extract(self
, url
):
30 mobj
= re
.match(self
._VALID
_URL
, url
)
31 track_id
= mobj
.group(1)
33 data
= {'ax': 1, 'ts': time
.time()}
34 data_encoded
= compat_urllib_parse
.urlencode(data
)
35 complete_url
= url
+ "?" + data_encoded
36 request
= compat_urllib_request
.Request(complete_url
)
37 response
, urlh
= self
._download
_webpage
_handle
(
38 request
, track_id
, 'Downloading webpage with the url')
39 cookie
= urlh
.headers
.get('Set-Cookie', '')
41 html_tracks
= self
._html
_search
_regex
(
42 r
'(?ms)<script type="application/json" id="displayList-data">\s*(.*?)\s*</script>',
45 track_list
= json
.loads(html_tracks
)
46 track
= track_list
['tracks'][0]
48 raise ExtractorError('Hypemachine contained invalid JSON.')
51 track_id
= track
['id']
52 artist
= track
['artist']
55 serve_url
= "http://hypem.com/serve/source/%s/%s" % (track_id
, key
)
56 request
= compat_urllib_request
.Request(
57 serve_url
, '', {'Content-Type': 'application/json'})
58 request
.add_header('cookie', cookie
)
59 song_data
= self
._download
_json
(request
, track_id
, 'Downloading metadata')
60 final_url
= song_data
["url"]