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