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