]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/ruutu.py
[spotify] Detect iframe embeds (#3430)
[yt-dlp.git] / yt_dlp / extractor / ruutu.py
index 5030c01cd6f6f6beb072684039521378ddd976f9..f5dadf27862a6a1c22d306299cb630550ed7061c 100644 (file)
@@ -1,5 +1,5 @@
-# coding: utf-8
-from __future__ import unicode_literals
+import json
+import re
 
 from .common import InfoExtractor
 from ..compat import compat_urllib_parse_urlparse
@@ -8,6 +8,8 @@
     ExtractorError,
     find_xpath_attr,
     int_or_none,
+    traverse_obj,
+    try_call,
     unified_strdate,
     url_or_none,
     xpath_attr,
@@ -123,6 +125,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)
 
@@ -200,9 +212,9 @@ def pv(name):
                 return node.get('value')
 
         if not formats:
-            if (not self._downloader.params.get('allow_unplayable_formats')
+            if (not self.get_param('allow_unplayable_formats')
                     and xpath_text(video_xml, './Clip/DRM', default=None)):
-                self.raise_no_formats('This video is DRM protected.', expected=True)
+                self.report_drm(video_id)
             ns_st_cds = pv('ns_st_cds')
             if ns_st_cds != 'free':
                 raise ExtractorError('This video is %s.' % ns_st_cds, expected=True)