viewlift.py 15 KB

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