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