]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/dw.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / dw.py
CommitLineData
add96eb9 1import urllib.parse
2
c8868a9d 3from .common import InfoExtractor
ac88d231
YCH
4from ..utils import (
5 int_or_none,
6 unified_strdate,
d98b006b 7 url_or_none,
ac88d231 8)
c8868a9d 9
10
11class DWIE(InfoExtractor):
df773c3d 12 _WORKING = False
13 _ENABLED = None # XXX: pass through to GenericIE
36bb63e0 14 IE_NAME = 'dw'
ac88d231 15 _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+(?:av|e)-(?P<id>\d+)'
91d6aafb 16 _TESTS = [{
17 # video
c8868a9d 18 'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
d98b006b 19 'md5': 'fb9dfd9520811d3ece80f04befd73428',
c8868a9d 20 'info_dict': {
21 'id': '19112290',
22 'ext': 'mp4',
23 'title': 'Intelligent light',
24 'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
d98b006b 25 'upload_date': '20160605',
add96eb9 26 },
91d6aafb 27 }, {
28 # audio
29 'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
30 'md5': '2814c9a1321c3a51f8a7aeb067a360dd',
31 'info_dict': {
32 'id': '19111941',
33 'ext': 'mp3',
34 'title': 'WorldLink: My business',
35 'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
36 'upload_date': '20160311',
add96eb9 37 },
ac88d231 38 }, {
6c0376fe 39 # DW documentaries, only last for one or two weeks
ac88d231
YCH
40 'url': 'http://www.dw.com/en/documentaries-welcome-to-the-90s-2016-05-21/e-19220158-9798',
41 'md5': '56b6214ef463bfb9a3b71aeb886f3cf1',
42 'info_dict': {
43 'id': '19274438',
44 'ext': 'mp4',
45 'title': 'Welcome to the 90s – Hip Hop',
46 'description': 'Welcome to the 90s - The Golden Decade of Hip Hop',
47 'upload_date': '20160521',
48 },
6c0376fe 49 'skip': 'Video removed',
91d6aafb 50 }]
c8868a9d 51
52 def _real_extract(self, url):
36bb63e0 53 media_id = self._match_id(url)
54 webpage = self._download_webpage(url, media_id)
c8868a9d 55 hidden_inputs = self._hidden_inputs(webpage)
56 title = hidden_inputs['media_title']
ac88d231 57 media_id = hidden_inputs.get('media_id') or media_id
c8868a9d 58
d98b006b 59 direct_url = url_or_none(hidden_inputs.get('file_name'))
60 if direct_url:
61 formats = [{'url': hidden_inputs['file_name']}]
62 else:
91d6aafb 63 formats = self._extract_smil_formats(
add96eb9 64 f'http://www.dw.com/smil/v-{media_id}', media_id,
91d6aafb 65 transform_source=lambda s: s.replace(
66 'rtmp://tv-od.dw.de/flash/',
67 'http://tv-download.dw.de/dwtv_video/flv/'))
91d6aafb 68
ac88d231
YCH
69 upload_date = hidden_inputs.get('display_date')
70 if not upload_date:
71 upload_date = self._html_search_regex(
72 r'<span[^>]+class="date">([0-9.]+)\s*\|', webpage,
73 'upload date', default=None)
74 upload_date = unified_strdate(upload_date)
75
c8868a9d 76 return {
36bb63e0 77 'id': media_id,
c8868a9d 78 'title': title,
79 'description': self._og_search_description(webpage),
80 'thumbnail': hidden_inputs.get('preview_image'),
81 'duration': int_or_none(hidden_inputs.get('file_duration')),
ac88d231 82 'upload_date': upload_date,
c8868a9d 83 'formats': formats,
84 }
36bb63e0 85
86
87class DWArticleIE(InfoExtractor):
df773c3d 88 _WORKING = False
89 _ENABLED = None # XXX: pass through to GenericIE
36bb63e0 90 IE_NAME = 'dw:article'
91 _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
92 _TEST = {
93 'url': 'http://www.dw.com/en/no-hope-limited-options-for-refugees-in-idomeni/a-19111009',
94 'md5': '8ca657f9d068bbef74d6fc38b97fc869',
95 'info_dict': {
96 'id': '19105868',
97 'ext': 'mp4',
98 'title': 'The harsh life of refugees in Idomeni',
99 'description': 'md5:196015cc7e48ebf474db9399420043c7',
100 'upload_date': '20160310',
add96eb9 101 },
36bb63e0 102 }
103
104 def _real_extract(self, url):
105 article_id = self._match_id(url)
106 webpage = self._download_webpage(url, article_id)
107 hidden_inputs = self._hidden_inputs(webpage)
108 media_id = hidden_inputs['media_id']
add96eb9 109 media_path = self._search_regex(rf'href="([^"]+av-{media_id})"\s+class="overlayLink"', webpage, 'media url')
110 media_url = urllib.parse.urljoin(url, media_path)
36bb63e0 111 return self.url_result(media_url, 'DW', media_id)