2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
15 class HiDiveIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?hidive\.com/stream/(?P<title>[^/]+)/(?P<key>[^/?#&]+)'
17 # Using X-Forwarded-For results in 403 HTTP error for HLS fragments,
18 # so disabling geo bypass completely
20 _NETRC_MACHINE = 'hidive'
21 _LOGIN_URL = 'https://www.hidive.com/account/login'
24 'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001',
26 'id': 'the-comic-artist-and-his-assistants/s01e001',
28 'title': 'the-comic-artist-and-his-assistants/s01e001',
29 'series': 'the-comic-artist-and-his-assistants',
34 'skip_download': True,
36 'skip': 'Requires Authentication',
39 def _real_initialize(self):
40 email, password = self._get_login_info()
44 webpage = self._download_webpage(self._LOGIN_URL, None)
45 form = self._search_regex(
46 r'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
47 webpage, 'login form')
48 data = self._hidden_inputs(form)
53 self._download_webpage(
54 self._LOGIN_URL, None, 'Logging in', data=urlencode_postdata(data))
56 def _real_extract(self, url):
57 mobj = re.match(self._VALID_URL, url)
58 title, key = mobj.group('title', 'key')
59 video_id = '%s/%s' % (title, key)
61 settings = self._download_json(
62 'https://www.hidive.com/play/settings', video_id,
63 data=urlencode_postdata({
66 'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783',
69 restriction = settings.get('restrictionReason')
70 if restriction == 'RegionRestricted':
71 self.raise_geo_restricted()
73 if restriction and restriction != 'None':
75 '%s said: %s' % (self.IE_NAME, restriction), expected=True)
79 for rendition_id, rendition in settings['renditions'].items():
80 bitrates = rendition.get('bitrates')
81 if not isinstance(bitrates, dict):
83 m3u8_url = bitrates.get('hls')
84 if not isinstance(m3u8_url, compat_str):
86 formats.extend(self._extract_m3u8_formats(
87 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
88 m3u8_id='%s-hls' % rendition_id, fatal=False))
89 cc_files = rendition.get('ccFiles')
90 if not isinstance(cc_files, list):
92 for cc_file in cc_files:
93 if not isinstance(cc_file, list) or len(cc_file) < 3:
97 if not isinstance(cc_lang, compat_str) or not isinstance(
100 subtitles.setdefault(cc_lang, []).append({
103 self._sort_formats(formats)
105 season_number = int_or_none(self._search_regex(
106 r's(\d+)', key, 'season number', default=None))
107 episode_number = int_or_none(self._search_regex(
108 r'e(\d+)', key, 'episode number', default=None))
113 'subtitles': subtitles,
116 'season_number': season_number,
117 'episode_number': episode_number,