]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/hotnewhiphop.py
80b48b1b3605a18fa11547ab890897b6b47ccaa5
1 from __future__
import unicode_literals
6 from .common
import InfoExtractor
15 class HotNewHipHopIE(InfoExtractor
):
16 _VALID_URL
= r
'http://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html'
18 'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html',
19 'file': '1435540.mp3',
20 'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
22 'title': 'Freddie Gibbs - Lay It Down'
26 def _real_extract(self
, url
):
27 m
= re
.match(self
._VALID
_URL
, url
)
28 video_id
= m
.group('id')
30 webpage_src
= self
._download
_webpage
(url
, video_id
)
32 video_url_base64
= self
._search
_regex
(
33 r
'data-path="(.*?)"', webpage_src
, u
'video URL', fatal
=False)
35 if video_url_base64
is None:
36 video_url
= self
._search
_regex
(
37 r
'"contentUrl" content="(.*?)"', webpage_src
, u
'video 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_src
).strip()
68 'thumbnail': self
._og
_search
_thumbnail
(webpage_src
),