]> jfr.im git - yt-dlp.git/commitdiff
[ruutu] Detect embeds (#3294)
authorTeemu Ikonen <redacted>
Tue, 5 Apr 2022 12:15:47 +0000 (15:15 +0300)
committerGitHub <redacted>
Tue, 5 Apr 2022 12:15:47 +0000 (05:15 -0700)
Authored by: tpikonen

yt_dlp/extractor/generic.py
yt_dlp/extractor/ruutu.py

index 65e803dd7061330030e4f7c3f8e0a9a17ea1ad5f..2c503e58176bd351958ce4ce305fe2cc92aa7bae 100644 (file)
 from .mainstreaming import MainStreamingIE
 from .gfycat import GfycatIE
 from .panopto import PanoptoBaseIE
+from .ruutu import RuutuIE
 
 
 class GenericIE(InfoExtractor):
@@ -2511,7 +2512,24 @@ class GenericIE(InfoExtractor):
                 'id': 'insert-a-quiz-into-a-panopto-video'
             },
             'playlist_count': 1
-        }
+        },
+        {
+            # Ruutu embed
+            'url': 'https://www.nelonen.fi/ohjelmat/madventures-suomi/2160731-riku-ja-tunna-lahtevat-peurajahtiin-tv-sta-tutun-biologin-kanssa---metsastysreissu-huipentuu-kasvissyojan-painajaiseen',
+            'md5': 'a2513a98d3496099e6eced40f7e6a14b',
+            'info_dict': {
+                'id': '4044426',
+                'ext': 'mp4',
+                'title': 'Riku ja Tunna lähtevät peurajahtiin tv:stä tutun biologin kanssa – metsästysreissu huipentuu kasvissyöjän painajaiseen!',
+                'thumbnail': r're:^https?://.+\.jpg$',
+                'duration': 108,
+                'series' : 'Madventures Suomi',
+                'description': 'md5:aa55b44bd06a1e337a6f1d0b46507381',
+                'categories': ['Matkailu', 'Elämäntyyli'],
+                'age_limit': 0,
+                'upload_date': '20220308',
+            },
+        },
     ]
 
     def report_following_redirect(self, new_url):
@@ -3737,6 +3755,12 @@ def _real_extract(self, url):
         panopto_urls = PanoptoBaseIE._extract_urls(webpage)
         if panopto_urls:
             return self.playlist_from_matches(panopto_urls, video_id, video_title)
+
+        # Look for Ruutu embeds
+        ruutu_url = RuutuIE._extract_url(webpage)
+        if ruutu_url:
+            return self.url_result(ruutu_url, RuutuIE)
+
         # Look for HTML5 media
         entries = self._parse_html5_media_entries(url, webpage, video_id, m3u8_id='hls')
         if entries:
index d9cf39d712e547668c906cf68bdc2f25b32da094..5a30e336066afe850b6811c201089bf429a18491 100644 (file)
@@ -1,6 +1,9 @@
 # coding: utf-8
 from __future__ import unicode_literals
 
+import json
+import re
+
 from .common import InfoExtractor
 from ..compat import compat_urllib_parse_urlparse
 from ..utils import (
@@ -8,6 +11,8 @@
     ExtractorError,
     find_xpath_attr,
     int_or_none,
+    traverse_obj,
+    try_call,
     unified_strdate,
     url_or_none,
     xpath_attr,
@@ -123,6 +128,16 @@ class RuutuIE(InfoExtractor):
     ]
     _API_BASE = 'https://gatling.nelonenmedia.fi'
 
+    @classmethod
+    def _extract_url(cls, webpage):
+        settings = try_call(
+            lambda: json.loads(re.search(
+                r'jQuery\.extend\(Drupal\.settings, ({.+?})\);', webpage).group(1), strict=False))
+        video_id = traverse_obj(settings, (
+            'mediaCrossbowSettings', 'file', 'field_crossbow_video_id', 'und', 0, 'value'))
+        if video_id:
+            return f'http://www.ruutu.fi/video/{video_id}'
+
     def _real_extract(self, url):
         video_id = self._match_id(url)