[dw] add support for audio pages
[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
7
8 class DWIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+av-(?P<id>\d+)'
10     _TESTS = [{
11         # video
12         'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
13         'md5': '7372046e1815c5a534b43f3c3c36e6e9',
14         'info_dict': {
15             'id': '19112290',
16             'ext': 'mp4',
17             'title': 'Intelligent light',
18             'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
19             'upload_date': '20160311',
20         }
21     }, {
22         # audio
23         'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
24         'md5': '2814c9a1321c3a51f8a7aeb067a360dd',
25         'info_dict': {
26             'id': '19111941',
27             'ext': 'mp3',
28             'title': 'WorldLink: My business',
29             'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
30             'upload_date': '20160311',
31         }
32     }]
33
34     def _real_extract(self, url):
35         video_id = self._match_id(url)
36
37         webpage = self._download_webpage(url, video_id)
38         hidden_inputs = self._hidden_inputs(webpage)
39         title = hidden_inputs['media_title']
40
41         formats = []
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' % video_id, video_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         else:
49             formats = [{'url': hidden_inputs['file_name']}]
50
51         return {
52             'id': video_id,
53             'title': title,
54             'description': self._og_search_description(webpage),
55             'thumbnail': hidden_inputs.get('preview_image'),
56             'duration': int_or_none(hidden_inputs.get('file_duration')),
57             'upload_date': hidden_inputs.get('display_date'),
58             'formats': formats,
59         }