]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hidive.py
1 from .common
import InfoExtractor
11 class HiDiveIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?:www\.)?hidive\.com/stream/(?P<id>(?P<title>[^/]+)/(?P<key>[^/?#&]+))'
13 # Using X-Forwarded-For results in 403 HTTP error for HLS fragments,
14 # so disabling geo bypass completely
16 _NETRC_MACHINE
= 'hidive'
17 _LOGIN_URL
= 'https://www.hidive.com/account/login'
20 'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001',
22 'id': 'the-comic-artist-and-his-assistants/s01e001',
24 'title': 'the-comic-artist-and-his-assistants/s01e001',
25 'series': 'the-comic-artist-and-his-assistants',
30 'skip_download': True,
32 'skip': 'Requires Authentication',
35 def _perform_login(self
, username
, password
):
36 webpage
= self
._download
_webpage
(self
._LOGIN
_URL
, None)
37 form
= self
._search
_regex
(
38 r
'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
39 webpage
, 'login form', default
=None)
42 data
= self
._hidden
_inputs
(form
)
47 login_webpage
= self
._download
_webpage
(
48 self
._LOGIN
_URL
, None, 'Logging in', data
=urlencode_postdata(data
))
49 # If the user has multiple profiles on their account, select one. For now pick the first profile.
50 profile_id
= self
._search
_regex
(r
'<button [^>]+?data-profile-id="(\w+)"', login_webpage
, 'profile_id')
51 if profile_id
is None:
52 return # If only one profile, Hidive auto-selects it
53 profile_id_hash
= self
._search
_regex
(r
'\<button [^>]+?data-hash="(\w+)"', login_webpage
, 'profile_id_hash')
54 self
._request
_webpage
(
55 'https://www.hidive.com/ajax/chooseprofile', None,
56 data
=urlencode_postdata({
57 'profileId': profile_id
,
58 'hash': profile_id_hash
,
59 'returnUrl': '/dashboard'
62 def _call_api(self
, video_id
, title
, key
, data
={}, **kwargs
):
67 'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783',
69 return self
._download
_json
(
70 'https://www.hidive.com/play/settings', video_id
,
71 data
=urlencode_postdata(data
), **kwargs
) or {}
73 def _real_extract(self
, url
):
74 video_id
, title
, key
= self
._match
_valid
_url
(url
).group('id', 'title', 'key')
75 settings
= self
._call
_api
(video_id
, title
, key
)
77 restriction
= settings
.get('restrictionReason')
78 if restriction
== 'RegionRestricted':
79 self
.raise_geo_restricted()
80 if restriction
and restriction
!= 'None':
82 '%s said: %s' % (self
.IE_NAME
, restriction
), expected
=True)
84 formats
, parsed_urls
= [], {None}
85 for rendition_id
, rendition
in settings
['renditions'].items():
86 audio
, version
, extra
= rendition_id
.split('_')
87 m3u8_url
= url_or_none(try_get(rendition
, lambda x
: x
['bitrates']['hls']))
88 if m3u8_url
not in parsed_urls
:
89 parsed_urls
.add(m3u8_url
)
90 frmt
= self
._extract
_m
3u8_formats
(
91 m3u8_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', m3u8_id
=rendition_id
, fatal
=False)
94 f
['format_note'] = f
'{version}, {extra}'
98 for rendition_id
, rendition
in settings
['renditions'].items():
99 audio
, version
, extra
= rendition_id
.split('_')
100 for cc_file
in rendition
.get('ccFiles') or []:
101 cc_url
= url_or_none(try_get(cc_file
, lambda x
: x
[2]))
102 cc_lang
= try_get(cc_file
, (lambda x
: x
[1].replace(' ', '-').lower(), lambda x
: x
[0]), str)
103 if cc_url
not in parsed_urls
and cc_lang
:
104 parsed_urls
.add(cc_url
)
105 subtitles
.setdefault(cc_lang
, []).append({'url': cc_url}
)
110 'subtitles': subtitles
,
113 'season_number': int_or_none(
114 self
._search
_regex
(r
's(\d+)', key
, 'season number', default
=None)),
115 'episode_number': int_or_none(
116 self
._search
_regex
(r
'e(\d+)', key
, 'episode number', default
=None)),
117 'http_headers': {'Referer': url}