]>
Commit | Line | Data |
---|---|---|
62f49dd3 S |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
62f49dd3 S |
4 | |
5 | from .common import InfoExtractor | |
6 | from ..compat import compat_str | |
7 | from ..utils import ( | |
8 | ExtractorError, | |
9 | int_or_none, | |
3052a30d | 10 | url_or_none, |
62f49dd3 S |
11 | urlencode_postdata, |
12 | ) | |
13 | ||
14 | ||
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 | |
19 | _GEO_BYPASS = False | |
e8e58c22 | 20 | _NETRC_MACHINE = 'hidive' |
e8e58c22 | 21 | _LOGIN_URL = 'https://www.hidive.com/account/login' |
62f49dd3 S |
22 | |
23 | _TESTS = [{ | |
24 | 'url': 'https://www.hidive.com/stream/the-comic-artist-and-his-assistants/s01e001', | |
25 | 'info_dict': { | |
26 | 'id': 'the-comic-artist-and-his-assistants/s01e001', | |
27 | 'ext': 'mp4', | |
28 | 'title': 'the-comic-artist-and-his-assistants/s01e001', | |
29 | 'series': 'the-comic-artist-and-his-assistants', | |
30 | 'season_number': 1, | |
31 | 'episode_number': 1, | |
32 | }, | |
33 | 'params': { | |
34 | 'skip_download': True, | |
62f49dd3 | 35 | }, |
e8e58c22 | 36 | 'skip': 'Requires Authentication', |
62f49dd3 S |
37 | }] |
38 | ||
e8e58c22 | 39 | def _real_initialize(self): |
68217024 | 40 | email, password = self._get_login_info() |
e8e58c22 RA |
41 | if email is None: |
42 | return | |
43 | ||
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) | |
49 | data.update({ | |
50 | 'Email': email, | |
51 | 'Password': password, | |
52 | }) | |
53 | self._download_webpage( | |
54 | self._LOGIN_URL, None, 'Logging in', data=urlencode_postdata(data)) | |
e8e58c22 | 55 | |
62f49dd3 | 56 | def _real_extract(self, url): |
5ad28e7f | 57 | mobj = self._match_valid_url(url) |
62f49dd3 S |
58 | title, key = mobj.group('title', 'key') |
59 | video_id = '%s/%s' % (title, key) | |
60 | ||
61 | settings = self._download_json( | |
62 | 'https://www.hidive.com/play/settings', video_id, | |
63 | data=urlencode_postdata({ | |
64 | 'Title': title, | |
65 | 'Key': key, | |
e8e58c22 | 66 | 'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783', |
62f49dd3 S |
67 | })) |
68 | ||
69 | restriction = settings.get('restrictionReason') | |
70 | if restriction == 'RegionRestricted': | |
71 | self.raise_geo_restricted() | |
72 | ||
73 | if restriction and restriction != 'None': | |
74 | raise ExtractorError( | |
75 | '%s said: %s' % (self.IE_NAME, restriction), expected=True) | |
76 | ||
77 | formats = [] | |
78 | subtitles = {} | |
79 | for rendition_id, rendition in settings['renditions'].items(): | |
80 | bitrates = rendition.get('bitrates') | |
81 | if not isinstance(bitrates, dict): | |
82 | continue | |
3052a30d S |
83 | m3u8_url = url_or_none(bitrates.get('hls')) |
84 | if not m3u8_url: | |
62f49dd3 S |
85 | continue |
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): | |
91 | continue | |
92 | for cc_file in cc_files: | |
93 | if not isinstance(cc_file, list) or len(cc_file) < 3: | |
94 | continue | |
95 | cc_lang = cc_file[0] | |
3052a30d S |
96 | cc_url = url_or_none(cc_file[2]) |
97 | if not isinstance(cc_lang, compat_str) or not cc_url: | |
62f49dd3 S |
98 | continue |
99 | subtitles.setdefault(cc_lang, []).append({ | |
100 | 'url': cc_url, | |
101 | }) | |
e8e58c22 | 102 | self._sort_formats(formats) |
62f49dd3 S |
103 | |
104 | season_number = int_or_none(self._search_regex( | |
105 | r's(\d+)', key, 'season number', default=None)) | |
106 | episode_number = int_or_none(self._search_regex( | |
107 | r'e(\d+)', key, 'episode number', default=None)) | |
108 | ||
109 | return { | |
110 | 'id': video_id, | |
111 | 'title': video_id, | |
112 | 'subtitles': subtitles, | |
113 | 'formats': formats, | |
114 | 'series': title, | |
115 | 'season_number': season_number, | |
116 | 'episode_number': episode_number, | |
117 | } |