]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/hidive.py
3 from .common
import InfoExtractor
13 class HiDiveIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?hidive\.com/stream/(?P<id>(?P<title>[^/]+)/(?P<key>[^/?#&]+))'
15 # Using X-Forwarded-For results in 403 HTTP error for HLS fragments,
16 # so disabling geo bypass completely
18 _NETRC_MACHINE
= 'hidive'
19 _LOGIN_URL
= 'https://www.hidive.com/account/login'
22 'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001',
24 'id': 'the-comic-artist-and-his-assistants/s01e001',
26 'title': 'the-comic-artist-and-his-assistants/s01e001',
27 'series': 'the-comic-artist-and-his-assistants',
32 'skip_download': True,
34 'skip': 'Requires Authentication',
37 def _perform_login(self
, username
, password
):
38 webpage
= self
._download
_webpage
(self
._LOGIN
_URL
, None)
39 form
= self
._search
_regex
(
40 r
'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
41 webpage
, 'login form', default
=None)
42 if not form
: # logged in
44 data
= self
._hidden
_inputs
(form
)
49 self
._download
_webpage
(
50 self
._LOGIN
_URL
, None, 'Logging in', data
=urlencode_postdata(data
))
52 def _call_api(self
, video_id
, title
, key
, data
={}, **kwargs
):
57 'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783',
59 return self
._download
_json
(
60 'https://www.hidive.com/play/settings', video_id
,
61 data
=urlencode_postdata(data
), **kwargs
) or {}
63 def _extract_subtitles_from_rendition(self
, rendition
, subtitles
, parsed_urls
):
64 for cc_file
in rendition
.get('ccFiles', []):
65 cc_url
= url_or_none(try_get(cc_file
, lambda x
: x
[2]))
66 # name is used since we cant distinguish subs with same language code
67 cc_lang
= try_get(cc_file
, (lambda x
: x
[1].replace(' ', '-').lower(), lambda x
: x
[0]), str)
68 if cc_url
not in parsed_urls
and cc_lang
:
69 parsed_urls
.add(cc_url
)
70 subtitles
.setdefault(cc_lang
, []).append({'url': cc_url}
)
72 def _get_subtitles(self
, url
, video_id
, title
, key
, parsed_urls
):
73 webpage
= self
._download
_webpage
(url
, video_id
, fatal
=False) or ''
75 for caption
in set(re
.findall(r
'data-captions=\"([^\"]+)\"', webpage
)):
76 renditions
= self
._call
_api
(
77 video_id
, title
, key
, {'Captions': caption}
, fatal
=False,
78 note
=f
'Downloading {caption} subtitle information').get('renditions') or {}
79 for rendition_id
, rendition
in renditions
.items():
80 self
._extract
_subtitles
_from
_rendition
(rendition
, subtitles
, parsed_urls
)
83 def _real_extract(self
, url
):
84 video_id
, title
, key
= self
._match
_valid
_url
(url
).group('id', 'title', 'key')
85 settings
= self
._call
_api
(video_id
, title
, key
)
87 restriction
= settings
.get('restrictionReason')
88 if restriction
== 'RegionRestricted':
89 self
.raise_geo_restricted()
90 if restriction
and restriction
!= 'None':
92 '%s said: %s' % (self
.IE_NAME
, restriction
), expected
=True)
94 formats
, parsed_urls
= [], {None}
95 for rendition_id
, rendition
in settings
['renditions'].items():
96 audio
, version
, extra
= rendition_id
.split('_')
97 m3u8_url
= url_or_none(try_get(rendition
, lambda x
: x
['bitrates']['hls']))
98 if m3u8_url
not in parsed_urls
:
99 parsed_urls
.add(m3u8_url
)
100 frmt
= self
._extract
_m
3u8_formats
(
101 m3u8_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', m3u8_id
=rendition_id
, fatal
=False)
103 f
['language'] = audio
104 f
['format_note'] = f
'{version}, {extra}'
110 'subtitles': self
.extract_subtitles(url
, video_id
, title
, key
, parsed_urls
),
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}