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