1 from __future__ import unicode_literals
5 from .common import InfoExtractor
6 from ..compat import compat_urllib_parse
14 class HotNewHipHopIE(InfoExtractor):
15 _VALID_URL = r'http://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html'
17 'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html',
18 'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
22 'title': 'Freddie Gibbs - Lay It Down'
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id)
30 video_url_base64 = self._search_regex(
31 r'data-path="(.*?)"', webpage, 'video URL', default=None)
33 if video_url_base64 is None:
34 video_url = self._search_regex(
35 r'"contentUrl" content="(.*?)"', webpage, 'content URL')
36 return self.url_result(video_url, ie='Youtube')
38 reqdata = compat_urllib_parse.urlencode([
40 ('mediaId', video_id),
42 r = sanitized_Request(
43 'http://www.hotnewhiphop.com/ajax/media/getActions/', data=reqdata)
44 r.add_header('Content-Type', 'application/x-www-form-urlencoded')
45 mkd = self._download_json(
46 r, video_id, note='Requesting media key',
47 errnote='Could not download media key')
48 if 'mediaKey' not in mkd:
49 raise ExtractorError('Did not get a media key')
51 redirect_url = base64.b64decode(video_url_base64).decode('utf-8')
52 redirect_req = HEADRequest(redirect_url)
53 req = self._request_webpage(
54 redirect_req, video_id,
55 note='Resolving final URL', errnote='Could not resolve final URL')
56 video_url = req.geturl()
57 if video_url.endswith('.html'):
58 raise ExtractorError('Redirect failed')
60 video_title = self._og_search_title(webpage).strip()
66 'thumbnail': self._og_search_thumbnail(webpage),