Merge branch 'akamai_pv' of https://github.com/remitamine/youtube-dl into remitamine...
[youtube-dl] / youtube_dl / extractor / dw.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6 from ..compat import compat_urlparse
7
8
9 class DWIE(InfoExtractor):
10     IE_NAME = 'dw'
11     _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+av-(?P<id>\d+)'
12     _TESTS = [{
13         # video
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         }
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     }]
35
36     def _real_extract(self, url):
37         media_id = self._match_id(url)
38         webpage = self._download_webpage(url, media_id)
39         hidden_inputs = self._hidden_inputs(webpage)
40         title = hidden_inputs['media_title']
41
42         if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
43             formats = self._extract_smil_formats(
44                 'http://www.dw.com/smil/v-%s' % media_id, media_id,
45                 transform_source=lambda s: s.replace(
46                     'rtmp://tv-od.dw.de/flash/',
47                     'http://tv-download.dw.de/dwtv_video/flv/'))
48             self._sort_formats(formats)
49         else:
50             formats = [{'url': hidden_inputs['file_name']}]
51
52         return {
53             'id': media_id,
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         }
61
62
63 class 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)