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