]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hypem.py
   5 from .common 
import InfoExtractor
 
  15 class HypemIE(InfoExtractor
): 
  16     """Information Extractor for hypem""" 
  17     _VALID_URL 
= r
'(?:http://)?(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)' 
  19     def _real_extract(self
, url
): 
  20         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  22             raise ExtractorError(u
'Invalid URL: %s' % url
) 
  23         track_id 
= mobj
.group(1) 
  25         data 
= { 'ax': 1, 'ts': time
.time() } 
  26         data_encoded 
= compat_urllib_parse
.urlencode(data
) 
  27         complete_url 
= url 
+ "?" + data_encoded
 
  28         request 
= compat_urllib_request
.Request(complete_url
) 
  29         response
, urlh 
= self
._download
_webpage
_handle
(request
, track_id
, u
'Downloading webpage with the url') 
  30         cookie 
= urlh
.headers
.get('Set-Cookie', '') 
  32         self
.report_extraction(track_id
) 
  34         html_tracks 
= self
._html
_search
_regex
(r
'<script type="application/json" id="displayList-data">(.*?)</script>', 
  35             response
, u
'tracks', flags
=re
.MULTILINE|re
.DOTALL
).strip() 
  37             track_list 
= json
.loads(html_tracks
) 
  38             track 
= track_list
[u
'tracks'][0] 
  40             raise ExtractorError(u
'Hypemachine contained invalid JSON.') 
  43         track_id 
= track
[u
"id"] 
  44         artist 
= track
[u
"artist"] 
  45         title 
= track
[u
"song"] 
  47         serve_url 
= "http://hypem.com/serve/source/%s/%s" % (compat_str(track_id
), compat_str(key
)) 
  48         request 
= compat_urllib_request
.Request(serve_url
, "" , {'Content-Type': 'application/json'}) 
  49         request
.add_header('cookie', cookie
) 
  50         song_data_json 
= self
._download
_webpage
(request
, track_id
, u
'Downloading metadata') 
  52             song_data 
= json
.loads(song_data_json
) 
  54             raise ExtractorError(u
'Hypemachine contained invalid JSON.') 
  55         final_url 
= song_data
[u
"url"]