]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hotnewhiphop.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  16 class HotNewHipHopIE(InfoExtractor
): 
  17     _VALID_URL 
= r
'http://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html' 
  19         'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html', 
  20         'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96', 
  24             'title': 'Freddie Gibbs - Lay It Down' 
  28     def _real_extract(self
, url
): 
  29         video_id 
= self
._match
_id
(url
) 
  30         webpage 
= self
._download
_webpage
(url
, video_id
) 
  32         video_url_base64 
= self
._search
_regex
( 
  33             r
'data-path="(.*?)"', webpage
, 'video URL', default
=None) 
  35         if video_url_base64 
is None: 
  36             video_url 
= self
._search
_regex
( 
  37                 r
'"contentUrl" content="(.*?)"', webpage
, 'content URL') 
  38             return self
.url_result(video_url
, ie
='Youtube') 
  40         reqdata 
= compat_urllib_parse
.urlencode([ 
  42             ('mediaId', video_id
), 
  44         r 
= compat_urllib_request
.Request( 
  45             'http://www.hotnewhiphop.com/ajax/media/getActions/', data
=reqdata
) 
  46         r
.add_header('Content-Type', 'application/x-www-form-urlencoded') 
  47         mkd 
= self
._download
_json
( 
  48             r
, video_id
, note
='Requesting media key', 
  49             errnote
='Could not download media key') 
  50         if 'mediaKey' not in mkd
: 
  51             raise ExtractorError('Did not get a media key') 
  53         redirect_url 
= base64
.b64decode(video_url_base64
).decode('utf-8') 
  54         redirect_req 
= HEADRequest(redirect_url
) 
  55         req 
= self
._request
_webpage
( 
  56             redirect_req
, video_id
, 
  57             note
='Resolving final URL', errnote
='Could not resolve final URL') 
  58         video_url 
= req
.geturl() 
  59         if video_url
.endswith('.html'): 
  60             raise ExtractorError('Redirect failed') 
  62         video_title 
= self
._og
_search
_title
(webpage
).strip() 
  68             'thumbnail': self
._og
_search
_thumbnail
(webpage
),