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