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