]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/dw.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / dw.py
index d740652f172c1dc9b61b19205af20b6721e10211..320e29bfdb9d0629b130f85a2472df34af55346e 100644 (file)
@@ -1,28 +1,29 @@
-# coding: utf-8
-from __future__ import unicode_literals
+import urllib.parse
 
 from .common import InfoExtractor
 from ..utils import (
     int_or_none,
     unified_strdate,
+    url_or_none,
 )
-from ..compat import compat_urlparse
 
 
 class DWIE(InfoExtractor):
+    _WORKING = False
+    _ENABLED = None  # XXX: pass through to GenericIE
     IE_NAME = 'dw'
     _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+(?:av|e)-(?P<id>\d+)'
     _TESTS = [{
         # video
         'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
-        'md5': '7372046e1815c5a534b43f3c3c36e6e9',
+        'md5': 'fb9dfd9520811d3ece80f04befd73428',
         'info_dict': {
             'id': '19112290',
             'ext': 'mp4',
             'title': 'Intelligent light',
             'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
-            'upload_date': '20160311',
-        }
+            'upload_date': '20160605',
+        },
     }, {
         # audio
         'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
@@ -33,7 +34,7 @@ class DWIE(InfoExtractor):
             'title': 'WorldLink: My business',
             'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
             'upload_date': '20160311',
-        }
+        },
     }, {
         # DW documentaries, only last for one or two weeks
         'url': 'http://www.dw.com/en/documentaries-welcome-to-the-90s-2016-05-21/e-19220158-9798',
@@ -55,15 +56,15 @@ def _real_extract(self, url):
         title = hidden_inputs['media_title']
         media_id = hidden_inputs.get('media_id') or media_id
 
-        if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
+        direct_url = url_or_none(hidden_inputs.get('file_name'))
+        if direct_url:
+            formats = [{'url': hidden_inputs['file_name']}]
+        else:
             formats = self._extract_smil_formats(
-                'http://www.dw.com/smil/v-%s' % media_id, media_id,
+                f'http://www.dw.com/smil/v-{media_id}', media_id,
                 transform_source=lambda s: s.replace(
                     'rtmp://tv-od.dw.de/flash/',
                     'http://tv-download.dw.de/dwtv_video/flv/'))
-            self._sort_formats(formats)
-        else:
-            formats = [{'url': hidden_inputs['file_name']}]
 
         upload_date = hidden_inputs.get('display_date')
         if not upload_date:
@@ -84,6 +85,8 @@ def _real_extract(self, url):
 
 
 class DWArticleIE(InfoExtractor):
+    _WORKING = False
+    _ENABLED = None  # XXX: pass through to GenericIE
     IE_NAME = 'dw:article'
     _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
     _TEST = {
@@ -95,7 +98,7 @@ class DWArticleIE(InfoExtractor):
             'title': 'The harsh life of refugees in Idomeni',
             'description': 'md5:196015cc7e48ebf474db9399420043c7',
             'upload_date': '20160310',
-        }
+        },
     }
 
     def _real_extract(self, url):
@@ -103,6 +106,6 @@ def _real_extract(self, url):
         webpage = self._download_webpage(url, article_id)
         hidden_inputs = self._hidden_inputs(webpage)
         media_id = hidden_inputs['media_id']
-        media_path = self._search_regex(r'href="([^"]+av-%s)"\s+class="overlayLink"' % media_id, webpage, 'media url')
-        media_url = compat_urlparse.urljoin(url, media_path)
+        media_path = self._search_regex(rf'href="([^"]+av-{media_id})"\s+class="overlayLink"', webpage, 'media url')
+        media_url = urllib.parse.urljoin(url, media_path)
         return self.url_result(media_url, 'DW', media_id)