]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/hotnewhiphop.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / hotnewhiphop.py
CommitLineData
99f770ca
PH
1from __future__ import unicode_literals
2
5b66de88
JMS
3import base64
4
5from .common import InfoExtractor
5c2266df 6from ..compat import compat_urllib_parse
5c40bba8 7from ..utils import (
99f770ca
PH
8 ExtractorError,
9 HEADRequest,
5c2266df 10 sanitized_Request,
99f770ca 11)
5b66de88
JMS
12
13
14class 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
99f770ca
PH
38 reqdata = compat_urllib_parse.urlencode([
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 }