]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/dw.py
[utils] Support a new form of date
[yt-dlp.git] / youtube_dl / extractor / dw.py
CommitLineData
c8868a9d 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..utils import int_or_none
36bb63e0 6from ..compat import compat_urlparse
c8868a9d 7
8
9class DWIE(InfoExtractor):
36bb63e0 10 IE_NAME = 'dw'
c8868a9d 11 _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+av-(?P<id>\d+)'
91d6aafb 12 _TESTS = [{
13 # video
c8868a9d 14 'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
15 'md5': '7372046e1815c5a534b43f3c3c36e6e9',
16 'info_dict': {
17 'id': '19112290',
18 'ext': 'mp4',
19 'title': 'Intelligent light',
20 'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
21 'upload_date': '20160311',
22 }
91d6aafb 23 }, {
24 # audio
25 'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
26 'md5': '2814c9a1321c3a51f8a7aeb067a360dd',
27 'info_dict': {
28 'id': '19111941',
29 'ext': 'mp3',
30 'title': 'WorldLink: My business',
31 'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
32 'upload_date': '20160311',
33 }
34 }]
c8868a9d 35
36 def _real_extract(self, url):
36bb63e0 37 media_id = self._match_id(url)
38 webpage = self._download_webpage(url, media_id)
c8868a9d 39 hidden_inputs = self._hidden_inputs(webpage)
40 title = hidden_inputs['media_title']
41
91d6aafb 42 if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
43 formats = self._extract_smil_formats(
36bb63e0 44 'http://www.dw.com/smil/v-%s' % media_id, media_id,
91d6aafb 45 transform_source=lambda s: s.replace(
46 'rtmp://tv-od.dw.de/flash/',
47 'http://tv-download.dw.de/dwtv_video/flv/'))
19dbaeec 48 self._sort_formats(formats)
91d6aafb 49 else:
50 formats = [{'url': hidden_inputs['file_name']}]
51
c8868a9d 52 return {
36bb63e0 53 'id': media_id,
c8868a9d 54 'title': title,
55 'description': self._og_search_description(webpage),
56 'thumbnail': hidden_inputs.get('preview_image'),
57 'duration': int_or_none(hidden_inputs.get('file_duration')),
58 'upload_date': hidden_inputs.get('display_date'),
59 'formats': formats,
60 }
36bb63e0 61
62
63class DWArticleIE(InfoExtractor):
64 IE_NAME = 'dw:article'
65 _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
66 _TEST = {
67 'url': 'http://www.dw.com/en/no-hope-limited-options-for-refugees-in-idomeni/a-19111009',
68 'md5': '8ca657f9d068bbef74d6fc38b97fc869',
69 'info_dict': {
70 'id': '19105868',
71 'ext': 'mp4',
72 'title': 'The harsh life of refugees in Idomeni',
73 'description': 'md5:196015cc7e48ebf474db9399420043c7',
74 'upload_date': '20160310',
75 }
76 }
77
78 def _real_extract(self, url):
79 article_id = self._match_id(url)
80 webpage = self._download_webpage(url, article_id)
81 hidden_inputs = self._hidden_inputs(webpage)
82 media_id = hidden_inputs['media_id']
83 media_path = self._search_regex(r'href="([^"]+av-%s)"\s+class="overlayLink"' % media_id, webpage, 'media url')
84 media_url = compat_urlparse.urljoin(url, media_path)
85 return self.url_result(media_url, 'DW', media_id)