2018-03-04 10:46:36 +00:00
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
int_or_none,
|
2021-09-15 02:04:54 +00:00
|
|
|
try_get,
|
2018-07-21 12:08:28 +00:00
|
|
|
url_or_none,
|
2018-03-04 10:46:36 +00:00
|
|
|
urlencode_postdata,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class HiDiveIE(InfoExtractor):
|
2021-10-06 05:23:22 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?hidive\.com/stream/(?P<id>(?P<title>[^/]+)/(?P<key>[^/?#&]+))'
|
2018-03-04 10:46:36 +00:00
|
|
|
# Using X-Forwarded-For results in 403 HTTP error for HLS fragments,
|
|
|
|
# so disabling geo bypass completely
|
|
|
|
_GEO_BYPASS = False
|
2018-05-24 10:53:42 +00:00
|
|
|
_NETRC_MACHINE = 'hidive'
|
|
|
|
_LOGIN_URL = 'https://www.hidive.com/account/login'
|
2018-03-04 10:46:36 +00:00
|
|
|
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'the-comic-artist-and-his-assistants/s01e001',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'the-comic-artist-and-his-assistants/s01e001',
|
|
|
|
'series': 'the-comic-artist-and-his-assistants',
|
|
|
|
'season_number': 1,
|
|
|
|
'episode_number': 1,
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
2018-05-24 10:53:42 +00:00
|
|
|
'skip': 'Requires Authentication',
|
2018-03-04 10:46:36 +00:00
|
|
|
}]
|
|
|
|
|
2022-03-18 20:53:33 +00:00
|
|
|
def _perform_login(self, username, password):
|
2018-05-24 10:53:42 +00:00
|
|
|
webpage = self._download_webpage(self._LOGIN_URL, None)
|
|
|
|
form = self._search_regex(
|
|
|
|
r'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
|
2022-07-26 13:22:18 +00:00
|
|
|
webpage, 'login form', default=None)
|
2023-02-12 03:47:52 +00:00
|
|
|
if not form:
|
2022-07-26 13:22:18 +00:00
|
|
|
return
|
2018-05-24 10:53:42 +00:00
|
|
|
data = self._hidden_inputs(form)
|
|
|
|
data.update({
|
2022-03-18 20:53:33 +00:00
|
|
|
'Email': username,
|
2018-05-24 10:53:42 +00:00
|
|
|
'Password': password,
|
|
|
|
})
|
2023-02-12 03:47:52 +00:00
|
|
|
login_webpage = self._download_webpage(
|
2018-05-24 10:53:42 +00:00
|
|
|
self._LOGIN_URL, None, 'Logging in', data=urlencode_postdata(data))
|
2023-02-12 03:47:52 +00:00
|
|
|
# If the user has multiple profiles on their account, select one. For now pick the first profile.
|
|
|
|
profile_id = self._search_regex(r'<button [^>]+?data-profile-id="(\w+)"', login_webpage, 'profile_id')
|
|
|
|
if profile_id is None:
|
|
|
|
return # If only one profile, Hidive auto-selects it
|
|
|
|
profile_id_hash = self._search_regex(r'\<button [^>]+?data-hash="(\w+)"', login_webpage, 'profile_id_hash')
|
|
|
|
self._request_webpage(
|
|
|
|
'https://www.hidive.com/ajax/chooseprofile', None,
|
|
|
|
data=urlencode_postdata({
|
|
|
|
'profileId': profile_id,
|
|
|
|
'hash': profile_id_hash,
|
|
|
|
'returnUrl': '/dashboard'
|
|
|
|
}))
|
2018-05-24 10:53:42 +00:00
|
|
|
|
2021-10-08 15:07:24 +00:00
|
|
|
def _call_api(self, video_id, title, key, data={}, **kwargs):
|
|
|
|
data = {
|
|
|
|
**data,
|
|
|
|
'Title': title,
|
|
|
|
'Key': key,
|
|
|
|
'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783',
|
|
|
|
}
|
|
|
|
return self._download_json(
|
|
|
|
'https://www.hidive.com/play/settings', video_id,
|
|
|
|
data=urlencode_postdata(data), **kwargs) or {}
|
|
|
|
|
2018-03-04 10:46:36 +00:00
|
|
|
def _real_extract(self, url):
|
2021-10-06 05:23:22 +00:00
|
|
|
video_id, title, key = self._match_valid_url(url).group('id', 'title', 'key')
|
2021-10-08 15:07:24 +00:00
|
|
|
settings = self._call_api(video_id, title, key)
|
2018-03-04 10:46:36 +00:00
|
|
|
|
2021-10-06 05:23:22 +00:00
|
|
|
restriction = settings.get('restrictionReason')
|
|
|
|
if restriction == 'RegionRestricted':
|
|
|
|
self.raise_geo_restricted()
|
|
|
|
if restriction and restriction != 'None':
|
|
|
|
raise ExtractorError(
|
|
|
|
'%s said: %s' % (self.IE_NAME, restriction), expected=True)
|
2018-03-04 10:46:36 +00:00
|
|
|
|
2021-10-10 05:36:23 +00:00
|
|
|
formats, parsed_urls = [], {None}
|
2021-10-06 05:23:22 +00:00
|
|
|
for rendition_id, rendition in settings['renditions'].items():
|
|
|
|
audio, version, extra = rendition_id.split('_')
|
|
|
|
m3u8_url = url_or_none(try_get(rendition, lambda x: x['bitrates']['hls']))
|
2021-10-08 15:07:24 +00:00
|
|
|
if m3u8_url not in parsed_urls:
|
|
|
|
parsed_urls.add(m3u8_url)
|
2021-09-15 02:04:54 +00:00
|
|
|
frmt = self._extract_m3u8_formats(
|
2021-10-06 05:23:22 +00:00
|
|
|
m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id=rendition_id, fatal=False)
|
2021-09-15 02:04:54 +00:00
|
|
|
for f in frmt:
|
|
|
|
f['language'] = audio
|
2021-10-06 05:23:22 +00:00
|
|
|
f['format_note'] = f'{version}, {extra}'
|
2021-09-15 02:04:54 +00:00
|
|
|
formats.extend(frmt)
|
2018-03-04 10:46:36 +00:00
|
|
|
|
2023-02-12 03:47:52 +00:00
|
|
|
subtitles = {}
|
|
|
|
for rendition_id, rendition in settings['renditions'].items():
|
|
|
|
audio, version, extra = rendition_id.split('_')
|
|
|
|
for cc_file in rendition.get('ccFiles') or []:
|
|
|
|
cc_url = url_or_none(try_get(cc_file, lambda x: x[2]))
|
|
|
|
cc_lang = try_get(cc_file, (lambda x: x[1].replace(' ', '-').lower(), lambda x: x[0]), str)
|
|
|
|
if cc_url not in parsed_urls and cc_lang:
|
|
|
|
parsed_urls.add(cc_url)
|
|
|
|
subtitles.setdefault(cc_lang, []).append({'url': cc_url})
|
|
|
|
|
2018-03-04 10:46:36 +00:00
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': video_id,
|
2023-02-12 03:47:52 +00:00
|
|
|
'subtitles': subtitles,
|
2018-03-04 10:46:36 +00:00
|
|
|
'formats': formats,
|
|
|
|
'series': title,
|
2021-10-06 05:23:22 +00:00
|
|
|
'season_number': int_or_none(
|
|
|
|
self._search_regex(r's(\d+)', key, 'season number', default=None)),
|
|
|
|
'episode_number': int_or_none(
|
|
|
|
self._search_regex(r'e(\d+)', key, 'episode number', default=None)),
|
2021-09-15 02:04:54 +00:00
|
|
|
'http_headers': {'Referer': url}
|
2018-03-04 10:46:36 +00:00
|
|
|
}
|