]>
Commit | Line | Data |
---|---|---|
99f770ca PH |
1 | from __future__ import unicode_literals |
2 | ||
5b66de88 JMS |
3 | import base64 |
4 | ||
5 | from .common import InfoExtractor | |
5c40bba8 | 6 | from ..utils import ( |
99f770ca PH |
7 | ExtractorError, |
8 | HEADRequest, | |
5c2266df | 9 | sanitized_Request, |
6e6bc8da | 10 | urlencode_postdata, |
99f770ca | 11 | ) |
5b66de88 JMS |
12 | |
13 | ||
14 | class HotNewHipHopIE(InfoExtractor): | |
5886b38d | 15 | _VALID_URL = r'https?://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html' |
6f5ac90c | 16 | _TEST = { |
99f770ca | 17 | 'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html', |
99f770ca PH |
18 | 'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96', |
19 | 'info_dict': { | |
5c40bba8 PH |
20 | 'id': '1435540', |
21 | 'ext': 'mp3', | |
99f770ca | 22 | 'title': 'Freddie Gibbs - Lay It Down' |
6f5ac90c PH |
23 | } |
24 | } | |
5b66de88 JMS |
25 | |
26 | def _real_extract(self, url): | |
5c40bba8 PH |
27 | video_id = self._match_id(url) |
28 | webpage = self._download_webpage(url, video_id) | |
5b66de88 | 29 | |
99f770ca | 30 | video_url_base64 = self._search_regex( |
5c40bba8 | 31 | r'data-path="(.*?)"', webpage, 'video URL', default=None) |
ed54491c | 32 | |
99f770ca PH |
33 | if video_url_base64 is None: |
34 | video_url = self._search_regex( | |
5c40bba8 | 35 | r'"contentUrl" content="(.*?)"', webpage, 'content URL') |
ed54491c | 36 | return self.url_result(video_url, ie='Youtube') |
5b66de88 | 37 | |
6e6bc8da | 38 | reqdata = urlencode_postdata([ |
99f770ca PH |
39 | ('mediaType', 's'), |
40 | ('mediaId', video_id), | |
41 | ]) | |
5c2266df | 42 | r = sanitized_Request( |
99f770ca PH |
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') | |
50 | ||
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') | |
5b66de88 | 59 | |
5c40bba8 | 60 | video_title = self._og_search_title(webpage).strip() |
5b66de88 | 61 | |
99f770ca PH |
62 | return { |
63 | 'id': video_id, | |
64 | 'url': video_url, | |
65 | 'title': video_title, | |
5c40bba8 | 66 | 'thumbnail': self._og_search_thumbnail(webpage), |
99f770ca | 67 | } |