]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/joj.py
[ie/tenplay] Add support for seasons (#7939)
[yt-dlp.git] / yt_dlp / extractor / joj.py
index a01411be1003463129c75228fd218e716bb7182f..ea46042404148b44c45c5f4292a36d43d070e780 100644 (file)
@@ -1,5 +1,3 @@
-import re
-
 from .common import InfoExtractor
 from ..compat import compat_str
 from ..utils import (
@@ -18,15 +16,26 @@ class JojIE(InfoExtractor):
                     )
                     (?P<id>[^/?#^]+)
                 '''
+    _EMBED_REGEX = [r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1']
     _TESTS = [{
         'url': 'https://media.joj.sk/embed/a388ec4c-6019-4a4a-9312-b1bee194e932',
         'info_dict': {
             'id': 'a388ec4c-6019-4a4a-9312-b1bee194e932',
             'ext': 'mp4',
             'title': 'NOVÉ BÝVANIE',
-            'thumbnail': r're:^https?://.*\.jpg$',
+            'thumbnail': r're:^https?://.*?$',
             'duration': 3118,
         }
+    }, {
+        'url': 'https://media.joj.sk/embed/CSM0Na0l0p1',
+        'info_dict': {
+            'id': 'CSM0Na0l0p1',
+            'ext': 'mp4',
+            'height': 576,
+            'title': 'Extrémne rodiny 2 - POKRAČOVANIE (2012/04/09 21:30:00)',
+            'duration': 3937,
+            'thumbnail': r're:^https?://.*?$',
+        }
     }, {
         'url': 'https://media.joj.sk/embed/9i1cxv',
         'only_matching': True,
@@ -38,24 +47,16 @@ class JojIE(InfoExtractor):
         'only_matching': True,
     }]
 
-    @staticmethod
-    def _extract_urls(webpage):
-        return [
-            mobj.group('url')
-            for mobj in re.finditer(
-                r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//media\.joj\.sk/embed/(?:(?!\1).)+)\1',
-                webpage)]
-
     def _real_extract(self, url):
         video_id = self._match_id(url)
 
         webpage = self._download_webpage(
             'https://media.joj.sk/embed/%s' % video_id, video_id)
 
-        title = self._search_regex(
-            (r'videoTitle\s*:\s*(["\'])(?P<title>(?:(?!\1).)+)\1',
-             r'<title>(?P<title>[^<]+)'), webpage, 'title',
-            default=None, group='title') or self._og_search_title(webpage)
+        title = (self._search_json(r'videoTitle\s*:', webpage, 'title', video_id,
+                                   contains_pattern=r'["\'].+["\']', default=None)
+                 or self._html_extract_title(webpage, default=None)
+                 or self._og_search_title(webpage))
 
         bitrates = self._parse_json(
             self._search_regex(
@@ -67,11 +68,13 @@ def _real_extract(self, url):
         for format_url in try_get(bitrates, lambda x: x['mp4'], list) or []:
             if isinstance(format_url, compat_str):
                 height = self._search_regex(
-                    r'(\d+)[pP]\.', format_url, 'height', default=None)
+                    r'(\d+)[pP]|(pal)\.', format_url, 'height', default=None)
+                if height == 'pal':
+                    height = 576
                 formats.append({
                     'url': format_url,
-                    'format_id': format_field(height, template='%sp'),
-                    'height': int(height),
+                    'format_id': format_field(height, None, '%sp'),
+                    'height': int_or_none(height),
                 })
         if not formats:
             playlist = self._download_xml(
@@ -90,7 +93,6 @@ def _real_extract(self, url):
                         r'(\d+)[pP]', format_id or path, 'height',
                         default=None)),
                 })
-        self._sort_formats(formats)
 
         thumbnail = self._og_search_thumbnail(webpage)