]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/sovietscloset.py
[ie/mlbtv] Fix extraction (#10296)
[yt-dlp.git] / yt_dlp / extractor / sovietscloset.py
index 64201c88c3e48e3003cd258a87cc5033699670cb..773ddd34458ab0837fb4f38b6f803f977a2f563d 100644 (file)
@@ -1,12 +1,5 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 from .common import InfoExtractor
-from ..utils import (
-    js_to_json,
-    try_get,
-    unified_timestamp
-)
+from ..utils import try_get, unified_timestamp
 
 
 class SovietsClosetBaseIE(InfoExtractor):
@@ -14,17 +7,7 @@ class SovietsClosetBaseIE(InfoExtractor):
 
     def parse_nuxt_jsonp(self, nuxt_jsonp_url, video_id, name):
         nuxt_jsonp = self._download_webpage(nuxt_jsonp_url, video_id, note=f'Downloading {name} __NUXT_JSONP__')
-        js, arg_keys, arg_vals = self._search_regex(
-            r'__NUXT_JSONP__\(.*?\(function\((?P<arg_keys>.*?)\)\{return\s(?P<js>\{.*?\})\}\((?P<arg_vals>.*?)\)',
-            nuxt_jsonp, '__NUXT_JSONP__', group=['js', 'arg_keys', 'arg_vals'])
-
-        args = dict(zip(arg_keys.split(','), arg_vals.split(',')))
-
-        for key, val in args.items():
-            if val in ('undefined', 'void 0'):
-                args[key] = 'null'
-
-        return self._parse_json(js_to_json(js, args), video_id)['data'][0]
+        return self._search_nuxt_data(nuxt_jsonp, video_id, '__NUXT_JSONP__')
 
     def video_meta(self, video_id, game_name, category_name, episode_number, stream_date):
         title = game_name
@@ -58,7 +41,7 @@ class SovietsClosetIE(SovietsClosetBaseIE):
     _TESTS = [
         {
             'url': 'https://sovietscloset.com/video/1337',
-            'md5': '11e58781c4ca5b283307aa54db5b3f93',
+            'md5': 'bd012b04b261725510ca5383074cdd55',
             'info_dict': {
                 'id': '1337',
                 'ext': 'mp4',
@@ -72,23 +55,24 @@ class SovietsClosetIE(SovietsClosetBaseIE):
                 'upload_date': '20170413',
                 'uploader_id': 'SovietWomble',
                 'uploader_url': 'https://www.twitch.tv/SovietWomble',
+                'duration': 7007,
                 'was_live': True,
                 'availability': 'public',
                 'series': 'The Witcher',
                 'season': 'Misc',
                 'episode_number': 13,
+                'episode': 'Episode 13',
             },
         },
         {
             'url': 'https://sovietscloset.com/video/1105',
-            'md5': '578b1958a379e7110ba38697042e9efb',
+            'md5': '89fa928f183893cb65a0b7be846d8a90',
             'info_dict': {
                 'id': '1105',
                 'ext': 'mp4',
-                'title': 'Arma 3 - Zeus Games #3',
+                'title': 'Arma 3 - Zeus Games #5',
                 'uploader': 'SovietWomble',
                 'thumbnail': r're:^https?://.*\.b-cdn\.net/c0e5e76f-3a93-40b4-bf01-12343c2eec5d/thumbnail\.jpg$',
-                'uploader': 'SovietWomble',
                 'creator': 'SovietWomble',
                 'release_timestamp': 1461157200,
                 'release_date': '20160420',
@@ -96,11 +80,13 @@ class SovietsClosetIE(SovietsClosetBaseIE):
                 'upload_date': '20160420',
                 'uploader_id': 'SovietWomble',
                 'uploader_url': 'https://www.twitch.tv/SovietWomble',
+                'duration': 8804,
                 'was_live': True,
                 'availability': 'public',
                 'series': 'Arma 3',
                 'season': 'Zeus Games',
-                'episode_number': 3,
+                'episode_number': 5,
+                'episode': 'Episode 5',
             },
         },
     ]
@@ -114,18 +100,24 @@ def _extract_bunnycdn_iframe(self, video_id, bunnycdn_id):
         thumbnail_url = self._search_regex(r'(https?://.*?thumbnail\.jpg)', iframe, 'thumbnail url')
 
         m3u8_formats = self._extract_m3u8_formats(m3u8_url, video_id, headers=self.MEDIADELIVERY_REFERER)
-        self._sort_formats(m3u8_formats)
+
+        if not m3u8_formats:
+            duration = None
+        else:
+            duration = self._extract_m3u8_vod_duration(
+                m3u8_formats[0]['url'], video_id, headers=self.MEDIADELIVERY_REFERER)
 
         return {
             'formats': m3u8_formats,
             'thumbnail': thumbnail_url,
+            'duration': duration,
         }
 
     def _real_extract(self, url):
         video_id = self._match_id(url)
         webpage = self._download_webpage(url, video_id)
 
-        static_assets_base = self._search_regex(r'staticAssetsBase:\"(.*?)\"', webpage, 'staticAssetsBase')
+        static_assets_base = self._search_regex(r'(/_nuxt/static/\d+)', webpage, 'staticAssetsBase')
         static_assets_base = f'https://sovietscloset.com{static_assets_base}'
 
         stream = self.parse_nuxt_jsonp(f'{static_assets_base}/video/{video_id}/payload.js', video_id, 'video')['stream']
@@ -184,7 +176,7 @@ def _real_extract(self, url):
 
         webpage = self._download_webpage(url, playlist_id)
 
-        static_assets_base = self._search_regex(r'staticAssetsBase:\"(.*?)\"', webpage, 'staticAssetsBase')
+        static_assets_base = self._search_regex(r'(/_nuxt/static/\d+)', webpage, 'staticAssetsBase')
         static_assets_base = f'https://sovietscloset.com{static_assets_base}'
 
         sovietscloset = self.parse_nuxt_jsonp(f'{static_assets_base}/payload.js', playlist_id, 'global')['games']