]>
Commit | Line | Data |
---|---|---|
5196b988 NJ |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
3d2623a8 | 4 | from ..networking import Request |
5196b988 NJ |
5 | from ..utils import ( |
6 | ExtractorError, | |
7 | int_or_none, | |
b5be6dd5 | 8 | js_to_json, |
2dc4970e | 9 | traverse_obj, |
bef9a9e5 | 10 | url_or_none, |
3d2623a8 | 11 | urlencode_postdata, |
5196b988 NJ |
12 | ) |
13 | ||
14 | ||
15 | class TubiTvIE(InfoExtractor): | |
bef9a9e5 | 16 | _VALID_URL = r'https?://(?:www\.)?tubitv\.com/(?P<type>video|movies|tv-shows)/(?P<id>\d+)' |
5196b988 NJ |
17 | _LOGIN_URL = 'http://tubitv.com/login' |
18 | _NETRC_MACHINE = 'tubitv' | |
4fe4bda2 | 19 | _TESTS = [{ |
bef9a9e5 | 20 | 'url': 'https://tubitv.com/movies/100004539/the-39-steps', |
3b55aaac | 21 | 'info_dict': { |
bef9a9e5 | 22 | 'id': '100004539', |
3b55aaac | 23 | 'ext': 'mp4', |
bef9a9e5 BG |
24 | 'title': 'The 39 Steps', |
25 | 'description': 'md5:bb2f2dd337f0dc58c06cb509943f54c8', | |
26 | 'uploader_id': 'abc2558d54505d4f0f32be94f2e7108c', | |
27 | 'release_year': 1935, | |
3b55aaac | 28 | 'thumbnail': r're:^https?://.+\.(jpe?g|png)$', |
bef9a9e5 | 29 | 'duration': 5187, |
3b55aaac | 30 | }, |
bef9a9e5 BG |
31 | 'params': {'skip_download': 'm3u8'}, |
32 | }, { | |
33 | 'url': 'https://tubitv.com/tv-shows/554628/s01-e01-rise-of-the-snakes', | |
34 | 'info_dict': { | |
35 | 'id': '554628', | |
36 | 'ext': 'mp4', | |
37 | 'title': 'S01:E01 - Rise of the Snakes', | |
38 | 'description': 'md5:ba136f586de53af0372811e783a3f57d', | |
39 | 'episode': 'Rise of the Snakes', | |
40 | 'episode_number': 1, | |
41 | 'season': 'Season 1', | |
42 | 'season_number': 1, | |
43 | 'uploader_id': '2a9273e728c510d22aa5c57d0646810b', | |
44 | 'release_year': 2011, | |
45 | 'thumbnail': r're:^https?://.+\.(jpe?g|png)$', | |
46 | 'duration': 1376, | |
47 | }, | |
48 | 'params': {'skip_download': 'm3u8'}, | |
3b55aaac | 49 | }, { |
9260cf1d | 50 | 'url': 'http://tubitv.com/video/283829/the_comedian_at_the_friday', |
f4dfa9a5 | 51 | 'md5': '43ac06be9326f41912dc64ccf7a80320', |
5196b988 | 52 | 'info_dict': { |
9260cf1d | 53 | 'id': '283829', |
5196b988 | 54 | 'ext': 'mp4', |
9260cf1d | 55 | 'title': 'The Comedian at The Friday', |
56 | 'description': 'A stand up comedian is forced to look at the decisions in his life while on a one week trip to the west coast.', | |
f4dfa9a5 | 57 | 'uploader_id': 'bc168bee0d18dd1cb3b86c68706ab434', |
5196b988 | 58 | }, |
3b55aaac | 59 | 'skip': 'Content Unavailable' |
4fe4bda2 RA |
60 | }, { |
61 | 'url': 'http://tubitv.com/tv-shows/321886/s01_e01_on_nom_stories', | |
62 | 'only_matching': True, | |
29f7c58a | 63 | }, { |
64 | 'url': 'https://tubitv.com/movies/560057/penitentiary?start=true', | |
65 | 'info_dict': { | |
66 | 'id': '560057', | |
67 | 'ext': 'mp4', | |
68 | 'title': 'Penitentiary', | |
69 | 'description': 'md5:8d2fc793a93cc1575ff426fdcb8dd3f9', | |
70 | 'uploader_id': 'd8fed30d4f24fcb22ec294421b9defc2', | |
71 | 'release_year': 1979, | |
72 | }, | |
3b55aaac | 73 | 'skip': 'Content Unavailable' |
4fe4bda2 | 74 | }] |
5196b988 | 75 | |
3b55aaac | 76 | # DRM formats are included only to raise appropriate error |
77 | _UNPLAYABLE_FORMATS = ('hlsv6_widevine', 'hlsv6_widevine_nonclearlead', 'hlsv6_playready_psshv0', | |
78 | 'hlsv6_fairplay', 'dash_widevine', 'dash_widevine_nonclearlead') | |
79 | ||
52efa4b3 | 80 | def _perform_login(self, username, password): |
5196b988 NJ |
81 | self.report_login() |
82 | form_data = { | |
83 | 'username': username, | |
84 | 'password': password, | |
85 | } | |
6e6bc8da | 86 | payload = urlencode_postdata(form_data) |
3d2623a8 | 87 | request = Request(self._LOGIN_URL, payload) |
88 | request.headers['Content-Type'] = 'application/x-www-form-urlencoded' | |
5196b988 NJ |
89 | login_page = self._download_webpage( |
90 | request, None, False, 'Wrong login info') | |
91 | if not re.search(r'id="tubi-logout"', login_page): | |
92 | raise ExtractorError( | |
93 | 'Login failed (invalid username/password)', expected=True) | |
94 | ||
5196b988 | 95 | def _real_extract(self, url): |
bef9a9e5 BG |
96 | video_id, video_type = self._match_valid_url(url).group('id', 'type') |
97 | webpage = self._download_webpage(f'https://tubitv.com/{video_type}/{video_id}/', video_id) | |
98 | video_data = self._search_json( | |
99 | r'window\.__data\s*=', webpage, 'data', video_id, | |
100 | transform_source=js_to_json)['video']['byId'][video_id] | |
5196b988 | 101 | |
cf9d6cfb | 102 | formats = [] |
3b55aaac | 103 | drm_formats = False |
ffcd62c2 | 104 | |
bef9a9e5 BG |
105 | for resource in traverse_obj(video_data, ('video_resources', lambda _, v: url_or_none(v['manifest']['url']))): |
106 | resource_type = resource.get('type') | |
107 | manifest_url = resource['manifest']['url'] | |
108 | if resource_type == 'dash': | |
109 | formats.extend(self._extract_mpd_formats(manifest_url, video_id, mpd_id=resource_type, fatal=False)) | |
110 | elif resource_type in ('hlsv3', 'hlsv6'): | |
111 | formats.extend(self._extract_m3u8_formats(manifest_url, video_id, 'mp4', m3u8_id=resource_type, fatal=False)) | |
112 | elif resource_type in self._UNPLAYABLE_FORMATS: | |
3b55aaac | 113 | drm_formats = True |
bef9a9e5 BG |
114 | else: |
115 | self.report_warning(f'Skipping unknown resource type "{resource_type}"') | |
3b55aaac | 116 | |
117 | if not formats and drm_formats: | |
118 | self.report_drm(video_id) | |
119 | elif not formats and not video_data.get('policy_match'): # policy_match is False if content was removed | |
120 | raise ExtractorError('This content is currently unavailable', expected=True) | |
ffcd62c2 | 121 | |
9260cf1d | 122 | subtitles = {} |
bef9a9e5 | 123 | for sub in traverse_obj(video_data, ('subtitles', lambda _, v: url_or_none(v['url']))): |
f4dfa9a5 | 124 | subtitles.setdefault(sub.get('lang', 'English'), []).append({ |
bef9a9e5 | 125 | 'url': self._proto_relative_url(sub['url']), |
9260cf1d | 126 | }) |
127 | ||
bef9a9e5 | 128 | title = traverse_obj(video_data, ('title', {str})) |
febff4c1 B |
129 | season_number, episode_number, episode_title = self._search_regex( |
130 | r'^S(\d+):E(\d+) - (.+)', title, 'episode info', fatal=False, group=(1, 2, 3), default=(None, None, None)) | |
131 | ||
5196b988 NJ |
132 | return { |
133 | 'id': video_id, | |
134 | 'title': title, | |
135 | 'formats': formats, | |
9260cf1d | 136 | 'subtitles': subtitles, |
febff4c1 B |
137 | 'season_number': int_or_none(season_number), |
138 | 'episode_number': int_or_none(episode_number), | |
bef9a9e5 BG |
139 | 'episode': episode_title, |
140 | **traverse_obj(video_data, { | |
141 | 'description': ('description', {str}), | |
142 | 'duration': ('duration', {int_or_none}), | |
143 | 'uploader_id': ('publisher_id', {str}), | |
144 | 'release_year': ('year', {int_or_none}), | |
145 | 'thumbnails': ('thumbnails', ..., {url_or_none}, {'url': {self._proto_relative_url}}), | |
146 | }), | |
5196b988 | 147 | } |
b5be6dd5 A |
148 | |
149 | ||
150 | class TubiTvShowIE(InfoExtractor): | |
bef9a9e5 | 151 | _WORKING = False |
b5be6dd5 A |
152 | _VALID_URL = r'https?://(?:www\.)?tubitv\.com/series/[0-9]+/(?P<show_name>[^/?#]+)' |
153 | _TESTS = [{ | |
154 | 'url': 'https://tubitv.com/series/3936/the-joy-of-painting-with-bob-ross?start=true', | |
155 | 'playlist_mincount': 390, | |
156 | 'info_dict': { | |
157 | 'id': 'the-joy-of-painting-with-bob-ross', | |
158 | } | |
159 | }] | |
160 | ||
161 | def _entries(self, show_url, show_name): | |
162 | show_webpage = self._download_webpage(show_url, show_name) | |
febff4c1 | 163 | |
b5be6dd5 | 164 | show_json = self._parse_json(self._search_regex( |
febff4c1 B |
165 | r'window\.__data\s*=\s*({[^<]+});\s*</script>', |
166 | show_webpage, 'data'), show_name, transform_source=js_to_json)['video'] | |
167 | ||
b5be6dd5 | 168 | for episode_id in show_json['fullContentById'].keys(): |
2dc4970e | 169 | if traverse_obj(show_json, ('byId', episode_id, 'type')) == 's': |
170 | continue | |
b5be6dd5 | 171 | yield self.url_result( |
bef9a9e5 | 172 | f'https://tubitv.com/tv-shows/{episode_id}/', |
b5be6dd5 A |
173 | ie=TubiTvIE.ie_key(), video_id=episode_id) |
174 | ||
175 | def _real_extract(self, url): | |
5ad28e7f | 176 | show_name = self._match_valid_url(url).group('show_name') |
b5be6dd5 | 177 | return self.playlist_result(self._entries(url, show_name), playlist_id=show_name) |