]>
Commit | Line | Data |
---|---|---|
5196b988 NJ |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
5196b988 NJ |
4 | from ..utils import ( |
5 | ExtractorError, | |
6 | int_or_none, | |
b5be6dd5 | 7 | js_to_json, |
5c2266df | 8 | sanitized_Request, |
6e6bc8da | 9 | urlencode_postdata, |
5196b988 NJ |
10 | ) |
11 | ||
12 | ||
13 | class TubiTvIE(InfoExtractor): | |
b5be6dd5 A |
14 | _VALID_URL = r'''(?x) |
15 | (?: | |
16 | tubitv:| | |
17 | https?://(?:www\.)?tubitv\.com/(?:video|movies|tv-shows)/ | |
18 | ) | |
19 | (?P<id>[0-9]+)''' | |
5196b988 NJ |
20 | _LOGIN_URL = 'http://tubitv.com/login' |
21 | _NETRC_MACHINE = 'tubitv' | |
68f17a9c | 22 | _GEO_COUNTRIES = ['US'] |
4fe4bda2 | 23 | _TESTS = [{ |
9260cf1d | 24 | 'url': 'http://tubitv.com/video/283829/the_comedian_at_the_friday', |
f4dfa9a5 | 25 | 'md5': '43ac06be9326f41912dc64ccf7a80320', |
5196b988 | 26 | 'info_dict': { |
9260cf1d | 27 | 'id': '283829', |
5196b988 | 28 | 'ext': 'mp4', |
9260cf1d | 29 | 'title': 'The Comedian at The Friday', |
30 | '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 | 31 | 'uploader_id': 'bc168bee0d18dd1cb3b86c68706ab434', |
5196b988 | 32 | }, |
4fe4bda2 RA |
33 | }, { |
34 | 'url': 'http://tubitv.com/tv-shows/321886/s01_e01_on_nom_stories', | |
35 | 'only_matching': True, | |
36 | }, { | |
37 | 'url': 'http://tubitv.com/movies/383676/tracker', | |
38 | 'only_matching': True, | |
29f7c58a | 39 | }, { |
40 | 'url': 'https://tubitv.com/movies/560057/penitentiary?start=true', | |
41 | 'info_dict': { | |
42 | 'id': '560057', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'Penitentiary', | |
45 | 'description': 'md5:8d2fc793a93cc1575ff426fdcb8dd3f9', | |
46 | 'uploader_id': 'd8fed30d4f24fcb22ec294421b9defc2', | |
47 | 'release_year': 1979, | |
48 | }, | |
49 | 'params': { | |
50 | 'skip_download': True, | |
51 | }, | |
4fe4bda2 | 52 | }] |
5196b988 | 53 | |
52efa4b3 | 54 | def _perform_login(self, username, password): |
5196b988 NJ |
55 | self.report_login() |
56 | form_data = { | |
57 | 'username': username, | |
58 | 'password': password, | |
59 | } | |
6e6bc8da | 60 | payload = urlencode_postdata(form_data) |
5c2266df | 61 | request = sanitized_Request(self._LOGIN_URL, payload) |
5196b988 NJ |
62 | request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
63 | login_page = self._download_webpage( | |
64 | request, None, False, 'Wrong login info') | |
65 | if not re.search(r'id="tubi-logout"', login_page): | |
66 | raise ExtractorError( | |
67 | 'Login failed (invalid username/password)', expected=True) | |
68 | ||
5196b988 NJ |
69 | def _real_extract(self, url): |
70 | video_id = self._match_id(url) | |
9260cf1d | 71 | video_data = self._download_json( |
72 | 'http://tubitv.com/oz/videos/%s/content' % video_id, video_id) | |
f4dfa9a5 | 73 | title = video_data['title'] |
5196b988 | 74 | |
cf9d6cfb | 75 | formats = [] |
76 | url = video_data['url'] | |
77 | # URL can be sometimes empty. Does this only happen when there is DRM? | |
78 | if url: | |
79 | formats = self._extract_m3u8_formats( | |
80 | self._proto_relative_url(url), | |
81 | video_id, 'mp4', 'm3u8_native') | |
19dbaeec | 82 | self._sort_formats(formats) |
5196b988 | 83 | |
f4dfa9a5 RA |
84 | thumbnails = [] |
85 | for thumbnail_url in video_data.get('thumbnails', []): | |
86 | if not thumbnail_url: | |
87 | continue | |
88 | thumbnails.append({ | |
89 | 'url': self._proto_relative_url(thumbnail_url), | |
90 | }) | |
91 | ||
9260cf1d | 92 | subtitles = {} |
f4dfa9a5 RA |
93 | for sub in video_data.get('subtitles', []): |
94 | sub_url = sub.get('url') | |
9260cf1d | 95 | if not sub_url: |
96 | continue | |
f4dfa9a5 RA |
97 | subtitles.setdefault(sub.get('lang', 'English'), []).append({ |
98 | 'url': self._proto_relative_url(sub_url), | |
9260cf1d | 99 | }) |
100 | ||
febff4c1 B |
101 | season_number, episode_number, episode_title = self._search_regex( |
102 | r'^S(\d+):E(\d+) - (.+)', title, 'episode info', fatal=False, group=(1, 2, 3), default=(None, None, None)) | |
103 | ||
5196b988 NJ |
104 | return { |
105 | 'id': video_id, | |
106 | 'title': title, | |
107 | 'formats': formats, | |
9260cf1d | 108 | 'subtitles': subtitles, |
f4dfa9a5 RA |
109 | 'thumbnails': thumbnails, |
110 | 'description': video_data.get('description'), | |
111 | 'duration': int_or_none(video_data.get('duration')), | |
112 | 'uploader_id': video_data.get('publisher_id'), | |
29f7c58a | 113 | 'release_year': int_or_none(video_data.get('year')), |
febff4c1 B |
114 | 'season_number': int_or_none(season_number), |
115 | 'episode_number': int_or_none(episode_number), | |
116 | 'episode_title': episode_title | |
5196b988 | 117 | } |
b5be6dd5 A |
118 | |
119 | ||
120 | class TubiTvShowIE(InfoExtractor): | |
121 | _VALID_URL = r'https?://(?:www\.)?tubitv\.com/series/[0-9]+/(?P<show_name>[^/?#]+)' | |
122 | _TESTS = [{ | |
123 | 'url': 'https://tubitv.com/series/3936/the-joy-of-painting-with-bob-ross?start=true', | |
124 | 'playlist_mincount': 390, | |
125 | 'info_dict': { | |
126 | 'id': 'the-joy-of-painting-with-bob-ross', | |
127 | } | |
128 | }] | |
129 | ||
130 | def _entries(self, show_url, show_name): | |
131 | show_webpage = self._download_webpage(show_url, show_name) | |
febff4c1 | 132 | |
b5be6dd5 | 133 | show_json = self._parse_json(self._search_regex( |
febff4c1 B |
134 | r'window\.__data\s*=\s*({[^<]+});\s*</script>', |
135 | show_webpage, 'data'), show_name, transform_source=js_to_json)['video'] | |
136 | ||
b5be6dd5 A |
137 | for episode_id in show_json['fullContentById'].keys(): |
138 | yield self.url_result( | |
139 | 'tubitv:%s' % episode_id, | |
140 | ie=TubiTvIE.ie_key(), video_id=episode_id) | |
141 | ||
142 | def _real_extract(self, url): | |
5ad28e7f | 143 | show_name = self._match_valid_url(url).group('show_name') |
b5be6dd5 | 144 | return self.playlist_result(self._entries(url, show_name), playlist_id=show_name) |