]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/limelight.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / limelight.py
index 90065094b60006641d72bffdc28f6ffea8d005b3..763a01448c4408acdb6692e61dd235bdb04090f9 100644 (file)
@@ -1,15 +1,15 @@
 import re
 
 from .common import InfoExtractor
-from ..compat import compat_HTTPError
+from ..networking.exceptions import HTTPError
 from ..utils import (
+    ExtractorError,
     determine_ext,
     float_or_none,
     int_or_none,
     smuggle_url,
     try_get,
     unsmuggle_url,
-    ExtractorError,
 )
 
 
@@ -32,8 +32,8 @@ def smuggle(url):
                 r'LimelightPlayer\.doLoad(Media|Channel|ChannelList)\(["\'](?P<id>[a-z0-9]{32})',
                 webpage):
             entries.append(cls.url_result(
-                smuggle('limelight:%s:%s' % (lm[kind], video_id)),
-                'Limelight%s' % kind, video_id))
+                smuggle(f'limelight:{lm[kind]}:{video_id}'),
+                f'Limelight{kind}', video_id))
         for mobj in re.finditer(
                 # As per [1] class attribute should be exactly equal to
                 # LimelightEmbeddedPlayerFlash but numerous examples seen
@@ -48,14 +48,14 @@ def smuggle(url):
                 ''', webpage):
             kind, video_id = mobj.group('kind'), mobj.group('id')
             entries.append(cls.url_result(
-                smuggle('limelight:%s:%s' % (kind, video_id)),
-                'Limelight%s' % kind.capitalize(), video_id))
+                smuggle(f'limelight:{kind}:{video_id}'),
+                f'Limelight{kind.capitalize()}', video_id))
         # http://support.3playmedia.com/hc/en-us/articles/115009517327-Limelight-Embedding-the-Audio-Description-Plugin-with-the-Limelight-Player-on-Your-Web-Page)
         for video_id in re.findall(
                 r'(?s)LimelightPlayerUtil\.embed\s*\(\s*{.*?\bmediaId["\']\s*:\s*["\'](?P<id>[a-z0-9]{32})',
                 webpage):
             entries.append(cls.url_result(
-                smuggle('limelight:media:%s' % video_id),
+                smuggle(f'limelight:media:{video_id}'),
                 LimelightMediaIE.ie_key(), video_id))
         return entries
 
@@ -66,11 +66,11 @@ def _call_playlist_service(self, item_id, method, fatal=True, referer=None):
         try:
             return self._download_json(
                 self._PLAYLIST_SERVICE_URL % (self._PLAYLIST_SERVICE_PATH, item_id, method),
-                item_id, 'Downloading PlaylistService %s JSON' % method,
+                item_id, f'Downloading PlaylistService {method} JSON',
                 fatal=fatal, headers=headers)
         except ExtractorError as e:
-            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
-                error = self._parse_json(e.cause.read().decode(), item_id)['detail']['contentAccessPermission']
+            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
+                error = self._parse_json(e.cause.response.read().decode(), item_id)['detail']['contentAccessPermission']
                 if error == 'CountryDisabled':
                     self.raise_geo_restricted()
                 raise ExtractorError(error, expected=True)
@@ -134,7 +134,7 @@ def _extract_info(self, pc, mobile, i, referer):
                     for cdn_host, http_host in CDN_HOSTS:
                         if cdn_host not in rtmp.group('host').lower():
                             continue
-                        http_url = 'http://%s/%s' % (http_host, rtmp.group('playpath')[4:])
+                        http_url = 'http://{}/{}'.format(http_host, rtmp.group('playpath')[4:])
                         urls.append(http_url)
                         if self._is_valid_url(http_url, video_id, http_format_id):
                             http_fmt = fmt.copy()
@@ -179,8 +179,6 @@ def _extract_info(self, pc, mobile, i, referer):
                     'ext': ext,
                 })
 
-        self._sort_formats(formats)
-
         subtitles = {}
         for flag in mobile_item.get('flags'):
             if flag == 'ClosedCaptions':
@@ -353,7 +351,7 @@ def _real_extract(self, url):
             channel_list_id, 'getMobileChannelListById')
 
         entries = [
-            self.url_result('limelight:channel:%s' % channel['id'], 'LimelightChannel')
+            self.url_result('limelight:channel:{}'.format(channel['id']), 'LimelightChannel')
             for channel in channel_list['channelList']]
 
         return self.playlist_result(