]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/mailru.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / mailru.py
index 5f30d0eaa8a4b45741cf51bfea3544ccf3049be4..cca678f14a4a2999b7f9263ff7f6c76a683a787a 100644 (file)
@@ -1,9 +1,9 @@
 import itertools
 import json
 import re
+import urllib.parse
 
 from .common import InfoExtractor
-from ..compat import compat_urllib_parse_unquote
 from ..utils import (
     int_or_none,
     parse_duration,
@@ -99,7 +99,7 @@ class MailRuIE(InfoExtractor):
         {
             'url': 'https://videoapi.my.mail.ru/videos/embed/mail/cloud-strife/Games/2009.html',
             'only_matching': True,
-        }
+        },
     ]
 
     def _real_extract(self, url):
@@ -108,7 +108,7 @@ def _real_extract(self, url):
 
         video_id = None
         if meta_id:
-            meta_url = 'https://my.mail.ru/+/video/meta/%s' % meta_id
+            meta_url = f'https://my.mail.ru/+/video/meta/{meta_id}'
         else:
             video_id = mobj.group('idv1')
             if not video_id:
@@ -137,20 +137,18 @@ def _real_extract(self, url):
         # Fallback old approach
         if not video_data:
             video_data = self._download_json(
-                'http://api.video.mail.ru/videos/%s.json?new=1' % video_id,
+                f'http://api.video.mail.ru/videos/{video_id}.json?new=1',
                 video_id, 'Downloading video JSON')
 
-        headers = {}
-
         video_key = self._get_cookies('https://my.mail.ru').get('video_key')
-        if video_key:
-            headers['Cookie'] = 'video_key=%s' % video_key.value
 
         formats = []
         for f in video_data['videos']:
             video_url = f.get('url')
             if not video_url:
                 continue
+            if video_key:
+                self._set_cookie(urllib.parse.urlparse(video_url).hostname, 'video_key', video_key.value)
             format_id = f.get('key')
             height = int_or_none(self._search_regex(
                 r'^(\d+)[pP]$', format_id, 'height', default=None)) if format_id else None
@@ -158,9 +156,7 @@ def _real_extract(self, url):
                 'url': video_url,
                 'format_id': format_id,
                 'height': height,
-                'http_headers': headers,
             })
-        self._sort_formats(formats)
 
         meta_data = video_data['meta']
         title = remove_end(meta_data['title'], '.mp4')
@@ -172,7 +168,7 @@ def _real_extract(self, url):
 
         acc_id = meta_data.get('accId')
         item_id = meta_data.get('itemId')
-        content_id = '%s_%s' % (acc_id, item_id) if acc_id and item_id else video_id
+        content_id = f'{acc_id}_{item_id}' if acc_id and item_id else video_id
 
         thumbnail = meta_data.get('poster')
         duration = int_or_none(meta_data.get('duration'))
@@ -195,7 +191,7 @@ class MailRuMusicSearchBaseIE(InfoExtractor):
     def _search(self, query, url, audio_id, limit=100, offset=0):
         search = self._download_json(
             'https://my.mail.ru/cgi-bin/my/ajax', audio_id,
-            'Downloading songs JSON page %d' % (offset // limit + 1),
+            f'Downloading songs JSON page {offset // limit + 1}',
             headers={
                 'Referer': url,
                 'X-Requested-With': 'XMLHttpRequest',
@@ -239,7 +235,7 @@ def _extract_track(t, fatal=True):
         artist = t.get('Author') or t.get('Author_Text_HTML')
 
         if track:
-            title = '%s - %s' % (artist, track) if artist else track
+            title = f'{artist} - {track}' if artist else track
         else:
             title = audio_id
 
@@ -310,7 +306,7 @@ class MailRuMusicSearchIE(MailRuMusicSearchBaseIE):
     }]
 
     def _real_extract(self, url):
-        query = compat_urllib_parse_unquote(self._match_id(url))
+        query = urllib.parse.unquote(self._match_id(url))
 
         entries = []