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