]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/svt.py
[extractor] Standardize `_live_title`
[yt-dlp.git] / yt_dlp / extractor / svt.py
index 5b377ea838add3a5bc046b58590906eb74995455..6ad01a912d527ee2160a445bacf0fe8bedbd9eaf 100644 (file)
@@ -119,7 +119,7 @@ def _extract_url(webpage):
             return mobj.group('url')
 
     def _real_extract(self, url):
-        mobj = re.match(self._VALID_URL, url)
+        mobj = self._match_valid_url(url)
         widget_id = mobj.group('widget_id')
         article_id = mobj.group('id')
 
@@ -146,7 +146,7 @@ class SVTPlayIE(SVTPlayBaseIE):
                         )
                         (?P<svt_id>[^/?#&]+)|
                         https?://(?:www\.)?(?:svtplay|oppetarkiv)\.se/(?:video|klipp|kanaler)/(?P<id>[^/?#&]+)
-                        (?:.*?modalId=(?P<modal_id>[\da-zA-Z-]+))?
+                        (?:.*?(?:modalId|id)=(?P<modal_id>[\da-zA-Z-]+))?
                     )
                     '''
     _TESTS = [{
@@ -168,7 +168,6 @@ class SVTPlayIE(SVTPlayBaseIE):
             },
         },
         'params': {
-            'format': 'bestvideo',
             # skip for now due to download test asserts that segment is > 10000 bytes and svt uses
             # init segments that are smaller
             # AssertionError: Expected test_SVTPlay_jNwpV9P.mp4 to be at least 9.77KiB, but it's only 864.00B
@@ -177,6 +176,9 @@ class SVTPlayIE(SVTPlayBaseIE):
     }, {
         'url': 'https://www.svtplay.se/video/30479064/husdrommar/husdrommar-sasong-8-designdrommar-i-stenungsund?modalId=8zVbDPA',
         'only_matching': True,
+    }, {
+        'url': 'https://www.svtplay.se/video/30684086/rapport/rapport-24-apr-18-00-7?id=e72gVpa',
+        'only_matching': True,
     }, {
         # geo restricted to Sweden
         'url': 'http://www.oppetarkiv.se/video/5219710/trollflojten',
@@ -201,10 +203,6 @@ class SVTPlayIE(SVTPlayBaseIE):
         'only_matching': True,
     }]
 
-    def _adjust_title(self, info):
-        if info['is_live']:
-            info['title'] = self._live_title(info['title'])
-
     def _extract_by_video_id(self, video_id, webpage=None):
         data = self._download_json(
             'https://api.svt.se/videoplayer-api/video/%s' % video_id,
@@ -218,11 +216,10 @@ def _extract_by_video_id(self, video_id, webpage=None):
             if not title:
                 title = video_id
             info_dict['title'] = title
-        self._adjust_title(info_dict)
         return info_dict
 
     def _real_extract(self, url):
-        mobj = re.match(self._VALID_URL, url)
+        mobj = self._match_valid_url(url)
         video_id = mobj.group('id')
         svt_id = mobj.group('svt_id') or mobj.group('modal_id')
 
@@ -249,7 +246,6 @@ def _real_extract(self, url):
                     'title': data['context']['dispatcher']['stores']['MetaStore']['title'],
                     'thumbnail': thumbnail,
                 })
-                self._adjust_title(info_dict)
                 return info_dict
 
             svt_id = try_get(
@@ -259,7 +255,7 @@ def _real_extract(self, url):
         if not svt_id:
             svt_id = self._search_regex(
                 (r'<video[^>]+data-video-id=["\']([\da-zA-Z-]+)',
-                 r'<[^>]+\bdata-rt=["\']top-area-play-button["\'][^>]+\bhref=["\'][^"\']*video/%s/[^"\']*\bmodalId=([\da-zA-Z-]+)' % re.escape(video_id),
+                 r'<[^>]+\bdata-rt=["\']top-area-play-button["\'][^>]+\bhref=["\'][^"\']*video/%s/[^"\']*\b(?:modalId|id)=([\da-zA-Z-]+)' % re.escape(video_id),
                  r'["\']videoSvtId["\']\s*:\s*["\']([\da-zA-Z-]+)',
                  r'["\']videoSvtId\\?["\']\s*:\s*\\?["\']([\da-zA-Z-]+)',
                  r'"content"\s*:\s*{.*?"id"\s*:\s*"([\da-zA-Z-]+)"',
@@ -298,7 +294,7 @@ def suitable(cls, url):
         return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTSeriesIE, cls).suitable(url)
 
     def _real_extract(self, url):
-        series_slug, season_id = re.match(self._VALID_URL, url).groups()
+        series_slug, season_id = self._match_valid_url(url).groups()
 
         series = self._download_json(
             'https://api.svt.se/contento/graphql', series_slug,
@@ -397,7 +393,7 @@ def suitable(cls, url):
         return False if SVTIE.suitable(url) or SVTPlayIE.suitable(url) else super(SVTPageIE, cls).suitable(url)
 
     def _real_extract(self, url):
-        path, display_id = re.match(self._VALID_URL, url).groups()
+        path, display_id = self._match_valid_url(url).groups()
 
         article = self._download_json(
             'https://api.svt.se/nss-api/page/' + path, display_id,