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