]>
Commit | Line | Data |
---|---|---|
62f49dd3 | 1 | from .common import InfoExtractor |
62f49dd3 S |
2 | from ..utils import ( |
3 | ExtractorError, | |
4 | int_or_none, | |
a8cb7eca | 5 | try_get, |
3052a30d | 6 | url_or_none, |
62f49dd3 S |
7 | urlencode_postdata, |
8 | ) | |
9 | ||
10 | ||
11 | class HiDiveIE(InfoExtractor): | |
705e7c20 | 12 | _VALID_URL = r'https?://(?:www\.)?hidive\.com/stream/(?P<id>(?P<title>[^/]+)/(?P<key>[^/?#&]+))' |
62f49dd3 S |
13 | # Using X-Forwarded-For results in 403 HTTP error for HLS fragments, |
14 | # so disabling geo bypass completely | |
15 | _GEO_BYPASS = False | |
e8e58c22 | 16 | _NETRC_MACHINE = 'hidive' |
e8e58c22 | 17 | _LOGIN_URL = 'https://www.hidive.com/account/login' |
62f49dd3 S |
18 | |
19 | _TESTS = [{ | |
20 | 'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001', | |
21 | 'info_dict': { | |
22 | 'id': 'the-comic-artist-and-his-assistants/s01e001', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'the-comic-artist-and-his-assistants/s01e001', | |
25 | 'series': 'the-comic-artist-and-his-assistants', | |
26 | 'season_number': 1, | |
27 | 'episode_number': 1, | |
28 | }, | |
29 | 'params': { | |
30 | 'skip_download': True, | |
62f49dd3 | 31 | }, |
e8e58c22 | 32 | 'skip': 'Requires Authentication', |
62f49dd3 S |
33 | }] |
34 | ||
52efa4b3 | 35 | def _perform_login(self, username, password): |
e8e58c22 RA |
36 | webpage = self._download_webpage(self._LOGIN_URL, None) |
37 | form = self._search_regex( | |
38 | r'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>', | |
2c646fe4 | 39 | webpage, 'login form', default=None) |
7708df8d | 40 | if not form: |
2c646fe4 | 41 | return |
e8e58c22 RA |
42 | data = self._hidden_inputs(form) |
43 | data.update({ | |
52efa4b3 | 44 | 'Email': username, |
e8e58c22 RA |
45 | 'Password': password, |
46 | }) | |
7708df8d | 47 | login_webpage = self._download_webpage( |
e8e58c22 | 48 | self._LOGIN_URL, None, 'Logging in', data=urlencode_postdata(data)) |
7708df8d | 49 | # If the user has multiple profiles on their account, select one. For now pick the first profile. |
e6ab678e | 50 | profile_id = self._search_regex( |
51 | r'<button [^>]+?data-profile-id="(\w+)"', login_webpage, 'profile id', default=None) | |
7708df8d AB |
52 | if profile_id is None: |
53 | return # If only one profile, Hidive auto-selects it | |
7708df8d AB |
54 | self._request_webpage( |
55 | 'https://www.hidive.com/ajax/chooseprofile', None, | |
56 | data=urlencode_postdata({ | |
57 | 'profileId': profile_id, | |
e6ab678e | 58 | 'hash': self._search_regex( |
59 | r'\<button [^>]+?data-hash="(\w+)"', login_webpage, 'profile id hash'), | |
7708df8d AB |
60 | 'returnUrl': '/dashboard' |
61 | })) | |
e8e58c22 | 62 | |
f2cad2e4 | 63 | def _call_api(self, video_id, title, key, data={}, **kwargs): |
64 | data = { | |
65 | **data, | |
66 | 'Title': title, | |
67 | 'Key': key, | |
68 | 'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783', | |
69 | } | |
70 | return self._download_json( | |
71 | 'https://www.hidive.com/play/settings', video_id, | |
72 | data=urlencode_postdata(data), **kwargs) or {} | |
73 | ||
62f49dd3 | 74 | def _real_extract(self, url): |
705e7c20 | 75 | video_id, title, key = self._match_valid_url(url).group('id', 'title', 'key') |
f2cad2e4 | 76 | settings = self._call_api(video_id, title, key) |
62f49dd3 | 77 | |
705e7c20 | 78 | restriction = settings.get('restrictionReason') |
79 | if restriction == 'RegionRestricted': | |
80 | self.raise_geo_restricted() | |
81 | if restriction and restriction != 'None': | |
82 | raise ExtractorError( | |
83 | '%s said: %s' % (self.IE_NAME, restriction), expected=True) | |
62f49dd3 | 84 | |
e8f726a5 | 85 | formats, parsed_urls = [], {None} |
705e7c20 | 86 | for rendition_id, rendition in settings['renditions'].items(): |
87 | audio, version, extra = rendition_id.split('_') | |
88 | m3u8_url = url_or_none(try_get(rendition, lambda x: x['bitrates']['hls'])) | |
f2cad2e4 | 89 | if m3u8_url not in parsed_urls: |
90 | parsed_urls.add(m3u8_url) | |
a8cb7eca | 91 | frmt = self._extract_m3u8_formats( |
705e7c20 | 92 | m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id=rendition_id, fatal=False) |
a8cb7eca AG |
93 | for f in frmt: |
94 | f['language'] = audio | |
705e7c20 | 95 | f['format_note'] = f'{version}, {extra}' |
a8cb7eca | 96 | formats.extend(frmt) |
62f49dd3 | 97 | |
7708df8d AB |
98 | subtitles = {} |
99 | for rendition_id, rendition in settings['renditions'].items(): | |
100 | audio, version, extra = rendition_id.split('_') | |
101 | for cc_file in rendition.get('ccFiles') or []: | |
102 | cc_url = url_or_none(try_get(cc_file, lambda x: x[2])) | |
103 | cc_lang = try_get(cc_file, (lambda x: x[1].replace(' ', '-').lower(), lambda x: x[0]), str) | |
104 | if cc_url not in parsed_urls and cc_lang: | |
105 | parsed_urls.add(cc_url) | |
106 | subtitles.setdefault(cc_lang, []).append({'url': cc_url}) | |
107 | ||
62f49dd3 S |
108 | return { |
109 | 'id': video_id, | |
110 | 'title': video_id, | |
7708df8d | 111 | 'subtitles': subtitles, |
62f49dd3 S |
112 | 'formats': formats, |
113 | 'series': title, | |
705e7c20 | 114 | 'season_number': int_or_none( |
115 | self._search_regex(r's(\d+)', key, 'season number', default=None)), | |
116 | 'episode_number': int_or_none( | |
117 | self._search_regex(r'e(\d+)', key, 'episode number', default=None)), | |
a8cb7eca | 118 | 'http_headers': {'Referer': url} |
62f49dd3 | 119 | } |