[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / hotnewhiphop.py
blob8573e8947d5c2b3cba35bcd4559ef47c43fed3f9
1 import base64
3 from .common import InfoExtractor
4 from ..networking import HEADRequest, Request
5 from ..utils import ExtractorError, urlencode_postdata
8 class HotNewHipHopIE(InfoExtractor):
9 _WORKING = False
10 _VALID_URL = r'https?://(?:www\.)?hotnewhiphop\.com/.*\.(?P<id>.*)\.html'
11 _TEST = {
12 'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html',
13 'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
14 'info_dict': {
15 'id': '1435540',
16 'ext': 'mp3',
17 'title': 'Freddie Gibbs - Lay It Down',
21 def _real_extract(self, url):
22 video_id = self._match_id(url)
23 webpage = self._download_webpage(url, video_id)
25 video_url_base64 = self._search_regex(
26 r'data-path="(.*?)"', webpage, 'video URL', default=None)
28 if video_url_base64 is None:
29 video_url = self._search_regex(
30 r'"contentUrl" content="(.*?)"', webpage, 'content URL')
31 return self.url_result(video_url, ie='Youtube')
33 reqdata = urlencode_postdata([
34 ('mediaType', 's'),
35 ('mediaId', video_id),
37 r = Request(
38 'http://www.hotnewhiphop.com/ajax/media/getActions/', data=reqdata)
39 r.headers['Content-Type'] = 'application/x-www-form-urlencoded'
40 mkd = self._download_json(
41 r, video_id, note='Requesting media key',
42 errnote='Could not download media key')
43 if 'mediaKey' not in mkd:
44 raise ExtractorError('Did not get a media key')
46 redirect_url = base64.b64decode(video_url_base64).decode('utf-8')
47 redirect_req = HEADRequest(redirect_url)
48 req = self._request_webpage(
49 redirect_req, video_id,
50 note='Resolving final URL', errnote='Could not resolve final URL')
51 video_url = req.url
52 if video_url.endswith('.html'):
53 raise ExtractorError('Redirect failed')
55 video_title = self._og_search_title(webpage).strip()
57 return {
58 'id': video_id,
59 'url': video_url,
60 'title': video_title,
61 'thumbnail': self._og_search_thumbnail(webpage),