]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/vevo.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / vevo.py
index 7715d683926562447290cc23df5409ef10a39c5c..8552a609c9fd76f6ce7f100e313ba5d0e47701b3 100644 (file)
@@ -2,7 +2,6 @@
 import re
 
 from .common import InfoExtractor
-from ..compat import compat_str
 from ..networking.exceptions import HTTPError
 from ..utils import (
     ExtractorError,
@@ -22,10 +21,10 @@ def _extract_json(self, webpage, video_id):
 
 
 class VevoIE(VevoBaseIE):
-    '''
+    """
     Accepts urls from vevo.com or in the format 'vevo:{id}'
     (currently used by MTVIE and MySpaceIE)
-    '''
+    """
     _VALID_URL = r'''(?x)
         (?:https?://(?:www\.)?vevo\.com/watch/(?!playlist|genre)(?:[^/]+/(?:[^/]+/)?)?|
            https?://cache\.vevo\.com/m/html/embed\.html\?video=|
@@ -166,14 +165,14 @@ def _initialize_api(self, video_id):
             data=json.dumps({
                 'client_id': 'SPupX1tvqFEopQ1YS6SS',
                 'grant_type': 'urn:vevo:params:oauth:grant-type:anonymous',
-            }).encode('utf-8'),
+            }).encode(),
             headers={
                 'Content-Type': 'application/json',
             })
 
         if re.search(r'(?i)THIS PAGE IS CURRENTLY UNAVAILABLE IN YOUR REGION', webpage):
             self.raise_geo_restricted(
-                '%s said: This page is currently unavailable in your region' % self.IE_NAME)
+                f'{self.IE_NAME} said: This page is currently unavailable in your region')
 
         auth_info = self._parse_json(webpage, video_id)
         self._api_url_template = self.http_scheme() + '//apiv2.vevo.com/%s?token=' + auth_info['legacy_token']
@@ -185,7 +184,7 @@ def _call_api(self, path, *args, **kwargs):
             if isinstance(e.cause, HTTPError):
                 errors = self._parse_json(e.cause.response.read().decode(), None)['errors']
                 error_message = ', '.join([error['message'] for error in errors])
-                raise ExtractorError('%s said: %s' % (self.IE_NAME, error_message), expected=True)
+                raise ExtractorError(f'{self.IE_NAME} said: {error_message}', expected=True)
             raise
         return data
 
@@ -195,11 +194,11 @@ def _real_extract(self, url):
         self._initialize_api(video_id)
 
         video_info = self._call_api(
-            'video/%s' % video_id, video_id, 'Downloading api video info',
+            f'video/{video_id}', video_id, 'Downloading api video info',
             'Failed to download video info')
 
         video_versions = self._call_api(
-            'video/%s/streams' % video_id, video_id,
+            f'video/{video_id}/streams', video_id,
             'Downloading video versions info',
             'Failed to download video versions info',
             fatal=False)
@@ -215,7 +214,7 @@ def _real_extract(self, url):
                 video_versions = [
                     value
                     for key, value in json_data['apollo']['data'].items()
-                    if key.startswith('%s.streams' % video_id)]
+                    if key.startswith(f'{video_id}.streams')]
 
         uploader = None
         artist = None
@@ -238,16 +237,16 @@ def _real_extract(self, url):
                 continue
             elif '.mpd' in version_url:
                 formats.extend(self._extract_mpd_formats(
-                    version_url, video_id, mpd_id='dash-%s' % version,
-                    note='Downloading %s MPD information' % version,
-                    errnote='Failed to download %s MPD information' % version,
+                    version_url, video_id, mpd_id=f'dash-{version}',
+                    note=f'Downloading {version} MPD information',
+                    errnote=f'Failed to download {version} MPD information',
                     fatal=False))
             elif '.m3u8' in version_url:
                 formats.extend(self._extract_m3u8_formats(
                     version_url, video_id, 'mp4', 'm3u8_native',
-                    m3u8_id='hls-%s' % version,
-                    note='Downloading %s m3u8 information' % version,
-                    errnote='Failed to download %s m3u8 information' % version,
+                    m3u8_id=f'hls-{version}',
+                    note=f'Downloading {version} m3u8 information',
+                    errnote=f'Failed to download {version} m3u8 information',
                     fatal=False))
             else:
                 m = re.search(r'''(?xi)
@@ -275,13 +274,13 @@ def _real_extract(self, url):
 
         track = video_info['title']
         if featured_artist:
-            artist = '%s ft. %s' % (artist, featured_artist)
-        title = '%s - %s' % (artist, track) if artist else track
+            artist = f'{artist} ft. {featured_artist}'
+        title = f'{artist} - {track}' if artist else track
 
         genres = video_info.get('genres')
         genre = (
             genres[0] if genres and isinstance(genres, list)
-            and isinstance(genres[0], compat_str) else None)
+            and isinstance(genres[0], str) else None)
 
         is_explicit = video_info.get('isExplicit')
         if is_explicit is True:
@@ -337,15 +336,15 @@ def _real_extract(self, url):
                 r'<meta[^>]+content=(["\'])vevo://video/(?P<id>.+?)\1[^>]*>',
                 webpage, 'video id', default=None, group='id')
             if video_id:
-                return self.url_result('vevo:%s' % video_id, VevoIE.ie_key())
+                return self.url_result(f'vevo:{video_id}', VevoIE.ie_key())
 
-        playlists = self._extract_json(webpage, playlist_id)['default']['%ss' % playlist_kind]
+        playlists = self._extract_json(webpage, playlist_id)['default'][f'{playlist_kind}s']
 
-        playlist = (list(playlists.values())[0]
+        playlist = (next(iter(playlists.values()))
                     if playlist_kind == 'playlist' else playlists[playlist_id])
 
         entries = [
-            self.url_result('vevo:%s' % src, VevoIE.ie_key())
+            self.url_result(f'vevo:{src}', VevoIE.ie_key())
             for src in playlist['isrcs']]
 
         return self.playlist_result(