]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/viewlift.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / viewlift.py
index b630f9a6d74ec92885e08950d88242aff1f5a592..7ac094f2f0d498f4bb8014589fe0bcbf117ed4c2 100644 (file)
@@ -1,7 +1,7 @@
 import json
 
 from .common import InfoExtractor
-from ..compat import compat_HTTPError
+from ..networking.exceptions import HTTPError
 from ..utils import (
     ExtractorError,
     int_or_none,
@@ -12,7 +12,7 @@
 
 class ViewLiftBaseIE(InfoExtractor):
     _API_BASE = 'https://prod-api.viewlift.com/'
-    _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'
+    _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'
     _SITE_MAP = {
         'ftfnext': 'lax',
         'funnyforfree': 'snagfilms',
@@ -27,6 +27,7 @@ class ViewLiftBaseIE(InfoExtractor):
         'snagxtreme': 'snagfilms',
         'theidentitytb': 'tampabay',
         'vayafilm': 'snagfilms',
+        'chorki': 'prothomalo',
     }
     _TOKENS = {}
 
@@ -46,8 +47,8 @@ def _call_api(self, site, path, video_id, url, query):
             return self._download_json(
                 self._API_BASE + path, video_id, headers={'Authorization': self._TOKENS.get(site)}, query=query)
         except ExtractorError as e:
-            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
-                webpage = e.cause.read().decode()
+            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
+                webpage = e.cause.response.read().decode()
                 try:
                     error_message = traverse_obj(json.loads(webpage), 'errorMessage', 'message')
                 except json.JSONDecodeError:
@@ -61,8 +62,8 @@ def _call_api(self, site, path, video_id, url, query):
 
 class ViewLiftEmbedIE(ViewLiftBaseIE):
     IE_NAME = 'viewlift:embed'
-    _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
-    _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?(?:%s)/embed/player.+?)\1' % ViewLiftBaseIE._DOMAINS_REGEX]
+    _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}})'
+    _EMBED_REGEX = [rf'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:embed\.)?(?:{ViewLiftBaseIE._DOMAINS_REGEX})/embed/player.+?)\1']
     _TESTS = [{
         'url': 'http://embed.snagfilms.com/embed/player?filmId=74849a00-85a9-11e1-9660-123139220831&w=500',
         'md5': '2924e9215c6eff7a55ed35b72276bd93',
@@ -73,7 +74,7 @@ class ViewLiftEmbedIE(ViewLiftBaseIE):
             'description': 'md5:b542bef32a6f657dadd0df06e26fb0c8',
             'timestamp': 1334350096,
             'upload_date': '20120413',
-        }
+        },
     }, {
         # invalid labels, 360p is better that 480p
         'url': 'http://www.snagfilms.com/embed/player?filmId=17ca0950-a74a-11e0-a92a-0026bb61d036',
@@ -97,7 +98,7 @@ def _real_extract(self, url):
 
         content_data = self._call_api(
             site, 'entitlement/video/status', film_id, url, {
-                'id': film_id
+                'id': film_id,
             })['video']
         gist = content_data['gist']
         title = gist['title']
@@ -119,7 +120,7 @@ def _real_extract(self, url):
                 'height', default=None))
             formats.append({
                 'url': video_asset_url,
-                'format_id': 'http%s' % ('-%d' % bitrate if bitrate else ''),
+                'format_id': 'http{}'.format(f'-{bitrate}' if bitrate else ''),
                 'tbr': bitrate,
                 'height': height,
                 'vcodec': video_asset.get('codec'),
@@ -134,7 +135,6 @@ def _real_extract(self, url):
                 'url': sub_url,
             })
 
-        self._sort_formats(formats)
         return {
             'id': film_id,
             'title': title,
@@ -153,7 +153,7 @@ def _real_extract(self, url):
 class ViewLiftIE(ViewLiftBaseIE):
     IE_NAME = 'viewlift'
     _API_BASE = 'https://prod-api-cached-2.viewlift.com/'
-    _VALID_URL = r'https?://(?:www\.)?(?P<domain>%s)(?P<path>(?:/(?:films/title|show|(?:news/)?videos?|watch))?/(?P<id>[^?#]+))' % ViewLiftBaseIE._DOMAINS_REGEX
+    _VALID_URL = rf'https?://(?:www\.)?(?P<domain>{ViewLiftBaseIE._DOMAINS_REGEX})(?P<path>(?:/(?:films/title|show|(?:news/)?videos?|watch))?/(?P<id>[^?#]+))'
     _TESTS = [{
         'url': 'http://www.snagfilms.com/films/title/lost_for_life',
         'md5': '19844f897b35af219773fd63bdec2942',
@@ -169,7 +169,7 @@ class ViewLiftIE(ViewLiftBaseIE):
             'age_limit': 14,
             'upload_date': '20150421',
             'timestamp': 1429656820,
-        }
+        },
     }, {
         'url': 'http://www.snagfilms.com/show/the_world_cut_project/india',
         'md5': 'e6292e5b837642bbda82d7f8bf3fbdfd',
@@ -183,7 +183,7 @@ class ViewLiftIE(ViewLiftBaseIE):
             'duration': 979,
             'timestamp': 1399478279,
             'upload_date': '20140507',
-        }
+        },
     }, {
         'url': 'http://main.snagfilms.com/augie_alone/s_2_ep_12_love',
         'info_dict': {
@@ -231,7 +231,6 @@ class ViewLiftIE(ViewLiftBaseIE):
             'description': 'md5:e28f2fb8680096a69c944d37c1fa5ffc',
             'thumbnail': r're:^https?://.*\.jpg$',
             'upload_date': '20211006',
-            'series': None
         },
         'params': {'skip_download': True},
     }, {  # Free film
@@ -243,7 +242,6 @@ class ViewLiftIE(ViewLiftBaseIE):
             'description': 'md5:605cba408e51a79dafcb824bdeded51e',
             'thumbnail': r're:^https?://.*\.jpg$',
             'upload_date': '20210827',
-            'series': None
         },
         'params': {'skip_download': True},
     }, {  # Free episode
@@ -255,7 +253,7 @@ class ViewLiftIE(ViewLiftBaseIE):
             'description': 'md5:ca30a682b4528d02a3eb6d0427dd0f87',
             'thumbnail': r're:^https?://.*\.jpg$',
             'upload_date': '20210830',
-            'series': 'Case Jaundice'
+            'series': 'Case Jaundice',
         },
         'params': {'skip_download': True},
     }, {  # Free video
@@ -267,7 +265,7 @@ class ViewLiftIE(ViewLiftBaseIE):
             'description': 'md5:9d21edc1827d32f8633eb67c2054fc31',
             'thumbnail': r're:^https?://.*\.jpg$',
             'upload_date': '20211006',
-            'series': 'Six (Hindi)'
+            'series': 'Six (Hindi)',
         },
         'params': {'skip_download': True},
     }, {  # Free episode
@@ -279,7 +277,7 @@ class ViewLiftIE(ViewLiftBaseIE):
             'description': 'md5:ef6ffae01a3d83438597367400f824ed',
             'thumbnail': r're:^https?://.*\.jpg$',
             'upload_date': '20211004',
-            'series': 'Asian Paints Moner Thikana'
+            'series': 'Asian Paints Moner Thikana',
         },
         'params': {'skip_download': True},
     }, {  # Free series
@@ -296,12 +294,39 @@ class ViewLiftIE(ViewLiftBaseIE):
         },
     }, {  # Premium movie
         'url': 'https://www.hoichoi.tv/movies/detective-2020',
-        'only_matching': True
+        'only_matching': True,
+    }, {  # Chorki Premium series
+        'url': 'https://www.chorki.com/bn/series/sinpaat',
+        'playlist_mincount': 7,
+        'info_dict': {
+            'id': 'bn/series/sinpaat',
+        },
+    }, {  # Chorki free movie
+        'url': 'https://www.chorki.com/bn/videos/bangla-movie-bikkhov',
+        'info_dict': {
+            'id': '564e755b-f5c7-4515-aee6-8959bee18c93',
+            'title': 'Bikkhov',
+            'ext': 'mp4',
+            'upload_date': '20230824',
+            'timestamp': 1692860553,
+            'categories': ['Action Movies', 'Salman Special'],
+            'tags': 'count:14',
+            'thumbnail': 'https://snagfilms-a.akamaihd.net/dd078ff5-b16e-45e4-9723-501b56b9df0a/images/2023/08/24/1692860450729_1920x1080_16x9Images.jpg',
+            'display_id': 'bn/videos/bangla-movie-bikkhov',
+            'description': 'md5:71492b086450625f4374a3eb824f27dc',
+            'duration': 8002,
+        },
+        'params': {
+            'skip_download': True,
+        },
+    }, {  # Chorki Premium movie
+        'url': 'https://www.chorki.com/bn/videos/something-like-an-autobiography',
+        'only_matching': True,
     }]
 
     @classmethod
     def suitable(cls, url):
-        return False if ViewLiftEmbedIE.suitable(url) else super(ViewLiftIE, cls).suitable(url)
+        return False if ViewLiftEmbedIE.suitable(url) else super().suitable(url)
 
     def _show_entries(self, domain, seasons):
         for season in seasons:
@@ -330,7 +355,7 @@ def _real_extract(self, url):
         film_id = next(m['contentData'][0]['gist']['id'] for m in modules if m.get('moduleType') == 'VideoDetailModule')
         return {
             '_type': 'url_transparent',
-            'url': 'http://%s/embed/player?filmId=%s' % (domain, film_id),
+            'url': f'http://{domain}/embed/player?filmId={film_id}',
             'id': film_id,
             'display_id': display_id,
             'ie_key': 'ViewLiftEmbed',