]> jfr.im git - yt-dlp.git/commitdiff
[extractor/odnoklassniki] Extract subtitles (#5920)
authorbashonly <redacted>
Mon, 2 Jan 2023 05:44:54 +0000 (05:44 +0000)
committerGitHub <redacted>
Mon, 2 Jan 2023 05:44:54 +0000 (05:44 +0000)
Closes #5744
Authored by: bashonly

yt_dlp/extractor/odnoklassniki.py

index 4f325f08784892a03fe9c77327ff46021e2611fa..4b73eed37e31fbc076cdb708827b496a6557ee30 100644 (file)
@@ -11,6 +11,7 @@
     int_or_none,
     qualities,
     smuggle_url,
+    traverse_obj,
     unescapeHTML,
     unified_strdate,
     unsmuggle_url,
@@ -153,6 +154,26 @@ class OdnoklassnikiIE(InfoExtractor):
             'title': 'Быковское крещение',
             'duration': 3038.181,
         },
+        'skip': 'HTTP Error 400',
+    }, {
+        'note': 'subtitles',
+        'url': 'https://ok.ru/video/4249587550747',
+        'info_dict': {
+            'id': '4249587550747',
+            'ext': 'mp4',
+            'title': 'Small Country An African Childhood (2020) (1080p) +subtitle',
+            'uploader': 'Sunflower Movies',
+            'uploader_id': '595802161179',
+            'upload_date': '20220816',
+            'duration': 6728,
+            'age_limit': 0,
+            'thumbnail': r're:^https?://i\.mycdn\.me/videoPreview\?.+',
+            'like_count': int,
+            'subtitles': dict,
+        },
+        'params': {
+            'skip_download': True,
+        },
     }, {
         'url': 'http://ok.ru/web-api/video/moviePlayer/20079905452',
         'only_matching': True,
@@ -202,6 +223,7 @@ class OdnoklassnikiIE(InfoExtractor):
             'like_count': 0,
             'duration': 10444,
         },
+        'skip': 'Site no longer embeds',
     }]
 
     @classmethod
@@ -294,6 +316,16 @@ def _extract_desktop(self, url):
 
         like_count = int_or_none(metadata.get('likeCount'))
 
+        subtitles = {}
+        for sub in traverse_obj(metadata, ('movie', 'subtitleTracks', ...), expected_type=dict):
+            sub_url = sub.get('url')
+            if not sub_url:
+                continue
+            subtitles.setdefault(sub.get('language') or 'en', []).append({
+                'url': sub_url,
+                'ext': 'vtt',
+            })
+
         info = {
             'id': video_id,
             'title': title,
@@ -305,6 +337,7 @@ def _extract_desktop(self, url):
             'like_count': like_count,
             'age_limit': age_limit,
             'start_time': start_time,
+            'subtitles': subtitles,
         }
 
         # pladform