]>
Commit | Line | Data |
---|---|---|
654fd03c S |
1 | from __future__ import unicode_literals |
2 | ||
4877ffc0 | 3 | import json |
654fd03c S |
4 | import re |
5 | ||
03339b7b | 6 | from .common import InfoExtractor |
4877ffc0 | 7 | from ..compat import compat_HTTPError |
654fd03c | 8 | from ..utils import ( |
9fbfc9bd | 9 | ExtractorError, |
654fd03c | 10 | int_or_none, |
57d67920 | 11 | parse_age_limit, |
5be76d1a | 12 | traverse_obj, |
654fd03c | 13 | ) |
03339b7b | 14 | |
654fd03c | 15 | |
67167920 | 16 | class ViewLiftBaseIE(InfoExtractor): |
4877ffc0 RA |
17 | _API_BASE = 'https://prod-api.viewlift.com/' |
18 | _DOMAINS_REGEX = r'(?:(?:main\.)?snagfilms|snagxtreme|funnyforfree|kiddovid|winnersview|(?:monumental|lax)sportsnetwork|vayafilm|failarmy|ftfnext|lnppass\.legapallacanestro|moviespree|app\.myoutdoortv|neoufitness|pflmma|theidentitytb)\.com|(?:hoichoi|app\.horseandcountry|kronon|marquee|supercrosslive)\.tv' | |
19 | _SITE_MAP = { | |
20 | 'ftfnext': 'lax', | |
21 | 'funnyforfree': 'snagfilms', | |
22 | 'hoichoi': 'hoichoitv', | |
23 | 'kiddovid': 'snagfilms', | |
24 | 'laxsportsnetwork': 'lax', | |
25 | 'legapallacanestro': 'lnp', | |
26 | 'marquee': 'marquee-tv', | |
27 | 'monumentalsportsnetwork': 'monumental-network', | |
28 | 'moviespree': 'bingeflix', | |
29 | 'pflmma': 'pfl', | |
30 | 'snagxtreme': 'snagfilms', | |
31 | 'theidentitytb': 'tampabay', | |
32 | 'vayafilm': 'snagfilms', | |
33 | } | |
34 | _TOKENS = {} | |
35 | ||
5be76d1a | 36 | def _fetch_token(self, site, url): |
37 | if self._TOKENS.get(site): | |
38 | return | |
39 | email, password = self._get_login_info(netrc_machine=site) | |
40 | if email: | |
41 | self.report_warning('Logging in using username and password is broken. %s' % self._LOGIN_HINTS['cookies']) | |
42 | ||
43 | cookies = self._get_cookies(url) | |
44 | if cookies and cookies.get('token'): | |
45 | self._TOKENS[site] = self._search_regex(r'22authorizationToken\%22:\%22([^\%]+)\%22', cookies['token'].value, 'token') | |
46 | if not self._TOKENS.get(site): | |
47 | self.raise_login_required('Cookies (not necessarily logged in) are needed to download from this website', method='cookies') | |
48 | ||
49 | def _call_api(self, site, path, video_id, url, query): | |
50 | self._fetch_token(site, url) | |
51 | try: | |
52 | return self._download_json( | |
53 | self._API_BASE + path, video_id, headers={'Authorization': self._TOKENS.get(site)}, query=query) | |
54 | except ExtractorError as e: | |
55 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403: | |
56 | webpage = e.cause.read().decode() | |
57 | try: | |
58 | error_message = traverse_obj(json.loads(webpage), 'errorMessage', 'message') | |
59 | except json.JSONDecodeError: | |
60 | raise ExtractorError(f'{site} said: {webpage}', cause=e.cause) | |
61 | if error_message: | |
62 | if 'has not purchased' in error_message: | |
63 | self.raise_login_required(method='cookies') | |
64 | raise ExtractorError(error_message, expected=True) | |
65 | raise | |
67167920 | 66 | |
67 | ||
68 | class ViewLiftEmbedIE(ViewLiftBaseIE): | |
4877ffc0 RA |
69 | IE_NAME = 'viewlift:embed' |
70 | _VALID_URL = r'https?://(?:(?:www|embed)\.)?(?P<domain>%s)/embed/player\?.*\bfilmId=(?P<id>[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12})' % ViewLiftBaseIE._DOMAINS_REGEX | |
7d7d4690 | 71 | _TESTS = [{ |
654fd03c S |
72 | 'url': 'http://embed.snagfilms.com/embed/player?filmId=74849a00-85a9-11e1-9660-123139220831&w=500', |
73 | 'md5': '2924e9215c6eff7a55ed35b72276bd93', | |
74 | 'info_dict': { | |
7d7d4690 | 75 | 'id': '74849a00-85a9-11e1-9660-123139220831', |
7d7d4690 | 76 | 'ext': 'mp4', |
77 | 'title': '#whilewewatch', | |
4877ffc0 RA |
78 | 'description': 'md5:b542bef32a6f657dadd0df06e26fb0c8', |
79 | 'timestamp': 1334350096, | |
80 | 'upload_date': '20120413', | |
7d7d4690 | 81 | } |
496ce6b3 S |
82 | }, { |
83 | # invalid labels, 360p is better that 480p | |
84 | 'url': 'http://www.snagfilms.com/embed/player?filmId=17ca0950-a74a-11e0-a92a-0026bb61d036', | |
85 | 'md5': '882fca19b9eb27ef865efeeaed376a48', | |
86 | 'info_dict': { | |
87 | 'id': '17ca0950-a74a-11e0-a92a-0026bb61d036', | |
88 | 'ext': 'mp4', | |
89 | 'title': 'Life in Limbo', | |
4877ffc0 RA |
90 | }, |
91 | 'skip': 'The video does not exist', | |
654fd03c S |
92 | }, { |
93 | 'url': 'http://www.snagfilms.com/embed/player?filmId=0000014c-de2f-d5d6-abcf-ffef58af0017', | |
94 | 'only_matching': True, | |
5be76d1a | 95 | }, { # Free film with langauge code |
96 | 'url': 'https://www.hoichoi.tv/bn/films/title/shuyopoka', | |
97 | 'info_dict': { | |
98 | 'id': '7a7a9d33-1f4c-4771-9173-ee4fb6dbf196', | |
99 | 'ext': 'mp4', | |
100 | 'title': 'Shuyopoka', | |
101 | 'description': 'md5:e28f2fb8680096a69c944d37c1fa5ffc', | |
102 | 'thumbnail': r're:^https?://.*\.jpg$', | |
103 | 'upload_date': '20211006', | |
104 | 'series': None | |
105 | }, | |
106 | 'params': {'skip_download': True}, | |
107 | }, { # Free film | |
108 | 'url': 'https://www.hoichoi.tv/films/title/dadu-no1', | |
109 | 'info_dict': { | |
110 | 'id': '0000015b-b009-d126-a1db-b81ff3780000', | |
111 | 'ext': 'mp4', | |
112 | 'title': 'Dadu No.1', | |
113 | 'description': 'md5:605cba408e51a79dafcb824bdeded51e', | |
114 | 'thumbnail': r're:^https?://.*\.jpg$', | |
115 | 'upload_date': '20210827', | |
116 | 'series': None | |
117 | }, | |
118 | 'params': {'skip_download': True}, | |
119 | }, { # Free episode | |
120 | 'url': 'https://www.hoichoi.tv/webseries/case-jaundice-s01-e01', | |
121 | 'info_dict': { | |
122 | 'id': 'f779e07c-30c8-459c-8612-5a834ab5e5ba', | |
123 | 'ext': 'mp4', | |
124 | 'title': 'Humans Vs. Corona', | |
125 | 'description': 'md5:ca30a682b4528d02a3eb6d0427dd0f87', | |
126 | 'thumbnail': r're:^https?://.*\.jpg$', | |
127 | 'upload_date': '20210830', | |
128 | 'series': 'Case Jaundice' | |
129 | }, | |
130 | 'params': {'skip_download': True}, | |
131 | }, { # Free video | |
132 | 'url': 'https://www.hoichoi.tv/videos/1549072415320-six-episode-02-hindi', | |
133 | 'info_dict': { | |
134 | 'id': 'b41fa1ce-aca6-47b6-b208-283ff0a2de30', | |
135 | 'ext': 'mp4', | |
136 | 'title': 'Woman in red - Hindi', | |
137 | 'description': 'md5:9d21edc1827d32f8633eb67c2054fc31', | |
138 | 'thumbnail': r're:^https?://.*\.jpg$', | |
139 | 'upload_date': '20211006', | |
140 | 'series': 'Six (Hindi)' | |
141 | }, | |
142 | 'params': {'skip_download': True}, | |
143 | }, { # Free episode | |
144 | 'url': 'https://www.hoichoi.tv/shows/watch-asian-paints-moner-thikana-online-season-1-episode-1', | |
145 | 'info_dict': { | |
146 | 'id': '1f45d185-8500-455c-b88d-13252307c3eb', | |
147 | 'ext': 'mp4', | |
148 | 'title': 'Jisshu Sengupta', | |
149 | 'description': 'md5:ef6ffae01a3d83438597367400f824ed', | |
150 | 'thumbnail': r're:^https?://.*\.jpg$', | |
151 | 'upload_date': '20211004', | |
152 | 'series': 'Asian Paints Moner Thikana' | |
153 | }, | |
154 | 'params': {'skip_download': True}, | |
155 | }, { # Free series | |
156 | 'url': 'https://www.hoichoi.tv/shows/watch-moner-thikana-bengali-web-series-online', | |
157 | 'playlist_mincount': 5, | |
158 | 'info_dict': { | |
159 | 'id': 'watch-moner-thikana-bengali-web-series-online', | |
160 | }, | |
161 | }, { # Premium series | |
162 | 'url': 'https://www.hoichoi.tv/shows/watch-byomkesh-bengali-web-series-online', | |
163 | 'playlist_mincount': 14, | |
164 | 'info_dict': { | |
165 | 'id': 'watch-byomkesh-bengali-web-series-online', | |
166 | }, | |
167 | }, { # Premium movie | |
168 | 'url': 'https://www.hoichoi.tv/movies/detective-2020', | |
169 | 'only_matching': True | |
7d7d4690 | 170 | }] |
03339b7b | 171 | |
7c197ad9 S |
172 | @staticmethod |
173 | def _extract_url(webpage): | |
174 | mobj = re.search( | |
67167920 | 175 | r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?(?:%s)/embed/player.+?)\1' % ViewLiftBaseIE._DOMAINS_REGEX, |
9fbfc9bd | 176 | webpage) |
7c197ad9 S |
177 | if mobj: |
178 | return mobj.group('url') | |
179 | ||
7e0480ae | 180 | def _real_extract(self, url): |
5ad28e7f | 181 | domain, film_id = self._match_valid_url(url).groups() |
4877ffc0 RA |
182 | site = domain.split('.')[-2] |
183 | if site in self._SITE_MAP: | |
184 | site = self._SITE_MAP[site] | |
5be76d1a | 185 | |
186 | content_data = self._call_api( | |
187 | site, 'entitlement/video/status', film_id, url, { | |
188 | 'id': film_id | |
189 | })['video'] | |
4877ffc0 RA |
190 | gist = content_data['gist'] |
191 | title = gist['title'] | |
192 | video_assets = content_data['streamingInfo']['videoAssets'] | |
9fbfc9bd | 193 | |
5be76d1a | 194 | hls_url = video_assets.get('hls') |
195 | formats, subtitles = [], {} | |
196 | if hls_url: | |
197 | formats, subtitles = self._extract_m3u8_formats_and_subtitles( | |
198 | hls_url, film_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False) | |
199 | ||
200 | for video_asset in video_assets.get('mpeg') or []: | |
4877ffc0 | 201 | video_asset_url = video_asset.get('url') |
5be76d1a | 202 | if not video_asset_url: |
654fd03c | 203 | continue |
4877ffc0 RA |
204 | bitrate = int_or_none(video_asset.get('bitrate')) |
205 | height = int_or_none(self._search_regex( | |
206 | r'^_?(\d+)[pP]$', video_asset.get('renditionValue'), | |
207 | 'height', default=None)) | |
208 | formats.append({ | |
209 | 'url': video_asset_url, | |
210 | 'format_id': 'http%s' % ('-%d' % bitrate if bitrate else ''), | |
211 | 'tbr': bitrate, | |
212 | 'height': height, | |
213 | 'vcodec': video_asset.get('codec'), | |
214 | }) | |
215 | ||
5be76d1a | 216 | subs = {} |
217 | for sub in traverse_obj(content_data, ('contentDetails', 'closedCaptions')) or []: | |
218 | sub_url = sub.get('url') | |
219 | if not sub_url: | |
220 | continue | |
221 | subs.setdefault(sub.get('language', 'English'), []).append({ | |
222 | 'url': sub_url, | |
223 | }) | |
4877ffc0 | 224 | |
5be76d1a | 225 | self._sort_formats(formats) |
226 | return { | |
4877ffc0 | 227 | 'id': film_id, |
654fd03c | 228 | 'title': title, |
4877ffc0 RA |
229 | 'description': gist.get('description'), |
230 | 'thumbnail': gist.get('videoImageUrl'), | |
231 | 'duration': int_or_none(gist.get('runtime')), | |
232 | 'age_limit': parse_age_limit(content_data.get('parentalRating')), | |
233 | 'timestamp': int_or_none(gist.get('publishDate'), 1000), | |
654fd03c | 234 | 'formats': formats, |
5be76d1a | 235 | 'subtitles': self._merge_subtitles(subs, subtitles), |
236 | 'categories': traverse_obj(content_data, ('categories', ..., 'title')), | |
237 | 'tags': traverse_obj(content_data, ('tags', ..., 'title')), | |
654fd03c S |
238 | } |
239 | ||
240 | ||
67167920 | 241 | class ViewLiftIE(ViewLiftBaseIE): |
4877ffc0 | 242 | IE_NAME = 'viewlift' |
5be76d1a | 243 | _API_BASE = 'https://prod-api-cached-2.viewlift.com/' |
4877ffc0 | 244 | _VALID_URL = r'https?://(?:www\.)?(?P<domain>%s)(?P<path>(?:/(?:films/title|show|(?:news/)?videos?|watch))?/(?P<id>[^?#]+))' % ViewLiftBaseIE._DOMAINS_REGEX |
242a998b | 245 | _TESTS = [{ |
654fd03c S |
246 | 'url': 'http://www.snagfilms.com/films/title/lost_for_life', |
247 | 'md5': '19844f897b35af219773fd63bdec2942', | |
248 | 'info_dict': { | |
249 | 'id': '0000014c-de2f-d5d6-abcf-ffef58af0017', | |
250 | 'display_id': 'lost_for_life', | |
251 | 'ext': 'mp4', | |
252 | 'title': 'Lost for Life', | |
57d67920 | 253 | 'description': 'md5:ea10b5a50405ae1f7b5269a6ec594102', |
ec85ded8 | 254 | 'thumbnail': r're:^https?://.*\.jpg', |
654fd03c | 255 | 'duration': 4489, |
57d67920 RA |
256 | 'categories': 'mincount:3', |
257 | 'age_limit': 14, | |
258 | 'upload_date': '20150421', | |
326ae4ff | 259 | 'timestamp': 1429656820, |
654fd03c | 260 | } |
242a998b S |
261 | }, { |
262 | 'url': 'http://www.snagfilms.com/show/the_world_cut_project/india', | |
263 | 'md5': 'e6292e5b837642bbda82d7f8bf3fbdfd', | |
264 | 'info_dict': { | |
265 | 'id': '00000145-d75c-d96e-a9c7-ff5c67b20000', | |
266 | 'display_id': 'the_world_cut_project/india', | |
267 | 'ext': 'mp4', | |
268 | 'title': 'India', | |
269 | 'description': 'md5:5c168c5a8f4719c146aad2e0dfac6f5f', | |
ec85ded8 | 270 | 'thumbnail': r're:^https?://.*\.jpg', |
242a998b | 271 | 'duration': 979, |
57d67920 RA |
272 | 'timestamp': 1399478279, |
273 | 'upload_date': '20140507', | |
242a998b | 274 | } |
326ae4ff S |
275 | }, { |
276 | 'url': 'http://main.snagfilms.com/augie_alone/s_2_ep_12_love', | |
277 | 'info_dict': { | |
278 | 'id': '00000148-7b53-de26-a9fb-fbf306f70020', | |
279 | 'display_id': 'augie_alone/s_2_ep_12_love', | |
280 | 'ext': 'mp4', | |
4877ffc0 RA |
281 | 'title': 'S. 2 Ep. 12 - Love', |
282 | 'description': 'Augie finds love.', | |
326ae4ff S |
283 | 'thumbnail': r're:^https?://.*\.jpg', |
284 | 'duration': 107, | |
4877ffc0 RA |
285 | 'upload_date': '20141012', |
286 | 'timestamp': 1413129540, | |
287 | 'age_limit': 17, | |
326ae4ff S |
288 | }, |
289 | 'params': { | |
290 | 'skip_download': True, | |
291 | }, | |
292 | }, { | |
293 | 'url': 'http://main.snagfilms.com/films/title/the_freebie', | |
294 | 'only_matching': True, | |
a9de9517 S |
295 | }, { |
296 | # Film is not playable in your area. | |
297 | 'url': 'http://www.snagfilms.com/films/title/inside_mecca', | |
298 | 'only_matching': True, | |
299 | }, { | |
300 | # Film is not available. | |
301 | 'url': 'http://www.snagfilms.com/show/augie_alone/flirting', | |
302 | 'only_matching': True, | |
67167920 | 303 | }, { |
304 | 'url': 'http://www.winnersview.com/videos/the-good-son', | |
305 | 'only_matching': True, | |
28bab133 YCH |
306 | }, { |
307 | # Was once Kaltura embed | |
308 | 'url': 'https://www.monumentalsportsnetwork.com/videos/john-carlson-postgame-2-25-15', | |
309 | 'only_matching': True, | |
4877ffc0 RA |
310 | }, { |
311 | 'url': 'https://www.marquee.tv/watch/sadlerswells-sacredmonsters', | |
312 | 'only_matching': True, | |
242a998b | 313 | }] |
654fd03c | 314 | |
2906631e S |
315 | @classmethod |
316 | def suitable(cls, url): | |
317 | return False if ViewLiftEmbedIE.suitable(url) else super(ViewLiftIE, cls).suitable(url) | |
318 | ||
5be76d1a | 319 | def _show_entries(self, domain, seasons): |
320 | for season in seasons: | |
321 | for episode in season.get('episodes') or []: | |
322 | path = traverse_obj(episode, ('gist', 'permalink')) | |
323 | if path: | |
324 | yield self.url_result(f'https://www.{domain}{path}', ie=self.ie_key()) | |
325 | ||
654fd03c | 326 | def _real_extract(self, url): |
5ad28e7f | 327 | domain, path, display_id = self._match_valid_url(url).groups() |
4877ffc0 RA |
328 | site = domain.split('.')[-2] |
329 | if site in self._SITE_MAP: | |
330 | site = self._SITE_MAP[site] | |
331 | modules = self._call_api( | |
5be76d1a | 332 | site, 'content/pages', display_id, url, { |
4877ffc0 RA |
333 | 'includeContent': 'true', |
334 | 'moduleOffset': 1, | |
335 | 'path': path, | |
336 | 'site': site, | |
337 | })['modules'] | |
5be76d1a | 338 | |
339 | seasons = next((m['contentData'][0]['seasons'] for m in modules if m.get('moduleType') == 'ShowDetailModule'), None) | |
340 | if seasons: | |
341 | return self.playlist_result(self._show_entries(domain, seasons), display_id) | |
342 | ||
4877ffc0 RA |
343 | film_id = next(m['contentData'][0]['gist']['id'] for m in modules if m.get('moduleType') == 'VideoDetailModule') |
344 | return { | |
345 | '_type': 'url_transparent', | |
346 | 'url': 'http://%s/embed/player?filmId=%s' % (domain, film_id), | |
347 | 'id': film_id, | |
348 | 'display_id': display_id, | |
349 | 'ie_key': 'ViewLiftEmbed', | |
350 | } |