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