[dw] Add new extractor
[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     _TEST = {
11         'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
12         'md5': '7372046e1815c5a534b43f3c3c36e6e9',
13         'info_dict': {
14             'id': '19112290',
15             'ext': 'mp4',
16             'title': 'Intelligent light',
17             'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
18             'upload_date': '20160311',
19         }
20     }
21
22     def _real_extract(self, url):
23         video_id = self._match_id(url)
24
25         formats = self._extract_smil_formats(
26             'http://www.dw.com/smil/v-%s' % video_id, video_id,
27             transform_source=lambda s: s.replace(
28                 'rtmp://tv-od.dw.de/flash/',
29                 'http://tv-download.dw.de/dwtv_video/flv/'))
30
31         webpage = self._download_webpage(url, video_id)
32         hidden_inputs = self._hidden_inputs(webpage)
33         title = hidden_inputs['media_title']
34
35         return {
36             'id': video_id,
37             'title': title,
38             'description': self._og_search_description(webpage),
39             'thumbnail': hidden_inputs.get('preview_image'),
40             'duration': int_or_none(hidden_inputs.get('file_duration')),
41             'upload_date': hidden_inputs.get('display_date'),
42             'formats': formats,
43         }