]>
Commit | Line | Data |
---|---|---|
0e3ae924 | 1 | # -*- coding: utf-8 -*- |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
0e3ae924 | 5 | |
6 | from .common import InfoExtractor | |
e89d7e30 | 7 | from ..utils import parse_filesize, ExtractorError |
0e3ae924 | 8 | |
9 | ||
10 | class TagesschauIE(InfoExtractor): | |
3c6ae8b5 | 11 | _VALID_URL = r'https?://(?:www\.)?tagesschau\.de/multimedia/(?:sendung/(ts|tsg|tt|nm|bab/bab)|video/video|tsvorzwanzig)(?P<id>-?[0-9]+)(?:~[-_a-zA-Z0-9]*)?\.html' |
0e3ae924 | 12 | |
13 | _TESTS = [{ | |
14 | 'url': 'http://www.tagesschau.de/multimedia/video/video1399128.html', | |
15 | 'md5': 'bcdeac2194fb296d599ce7929dfa4009', | |
16 | 'info_dict': { | |
17 | 'id': '1399128', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'Harald Range, Generalbundesanwalt, zu den Ermittlungen', | |
20 | 'description': 'md5:69da3c61275b426426d711bde96463ab', | |
21 | 'thumbnail': 're:^http:.*\.jpg$', | |
22 | }, | |
045c4884 PH |
23 | }, { |
24 | 'url': 'http://www.tagesschau.de/multimedia/sendung/ts-5727.html', | |
25 | 'md5': '3c54c1f6243d279b706bde660ceec633', | |
26 | 'info_dict': { | |
27 | 'id': '5727', | |
28 | 'ext': 'mp4', | |
29 | 'description': 'md5:695c01bfd98b7e313c501386327aea59', | |
30 | 'title': 'Sendung: tagesschau \t04.12.2014 20:00 Uhr', | |
31 | 'thumbnail': 're:^http:.*\.jpg$', | |
32 | } | |
e89d7e30 RH |
33 | }, { |
34 | 'url': 'http://www.tagesschau.de/multimedia/sendung/tsg-3771.html', | |
35 | 'md5': '90757268b49ef56deae90c7b48928d58', | |
36 | 'info_dict': { | |
37 | 'id': '3771', | |
38 | 'ext': 'mp4', | |
726adc43 | 39 | 'description': None, |
e89d7e30 RH |
40 | 'title': 'Sendung: tagesschau (mit Gebärdensprache) \t14.07.2015 20:00 Uhr', |
41 | 'thumbnail': 're:^http:.*\.jpg$', | |
42 | } | |
43 | }, { | |
44 | 'url': 'http://www.tagesschau.de/multimedia/sendung/tt-3827.html', | |
45 | 'md5': '6e3ebdc75e8d67da966a8d06721eda71', | |
46 | 'info_dict': { | |
47 | 'id': '3827', | |
48 | 'ext': 'mp4', | |
49 | 'description': 'md5:d511d0e278b0ad341a95ad9ab992ce66', | |
50 | 'title': 'Sendung: tagesthemen \t14.07.2015 22:15 Uhr', | |
51 | 'thumbnail': 're:^http:.*\.jpg$', | |
52 | } | |
53 | }, { | |
54 | 'url': 'http://www.tagesschau.de/multimedia/sendung/nm-3475.html', | |
55 | 'md5': '8a8875a568f0a5ae5ceef93c501a225f', | |
56 | 'info_dict': { | |
57 | 'id': '3475', | |
58 | 'ext': 'mp4', | |
59 | 'description': 'md5:ed149f5649cda3dac86813a9d777e131', | |
60 | 'title': 'Sendung: nachtmagazin \t15.07.2015 00:15 Uhr', | |
61 | 'thumbnail': 're:^http:.*\.jpg$', | |
62 | } | |
63 | }, { | |
64 | 'url': 'http://www.tagesschau.de/multimedia/tsvorzwanzig-959.html', | |
65 | 'md5': 'be4d6f0421f2acd8abe25ea29f6f015b', | |
66 | 'info_dict': { | |
67 | 'id': '959', | |
68 | 'ext': 'mp4', | |
726adc43 | 69 | 'description': None, |
e89d7e30 RH |
70 | 'title': 'Sendung: tagesschau vor 20 Jahren \t14.07.2015 22:45 Uhr', |
71 | 'thumbnail': 're:^http:.*\.jpg$', | |
72 | } | |
3c6ae8b5 RH |
73 | }, { |
74 | 'url': 'http://www.tagesschau.de/multimedia/sendung/bab/bab-3299~_bab-sendung-209.html', | |
75 | 'md5': '42e3757018d9908581481a80cc1806da', | |
76 | 'info_dict': { | |
77 | 'id': '3299', | |
78 | 'ext': 'mp4', | |
726adc43 | 79 | 'description': None, |
3c6ae8b5 RH |
80 | 'title': 'Nach dem Referendum: Schaltgespräch nach Athen', |
81 | 'thumbnail': 're:^http:.*\.jpg$', | |
82 | } | |
4a5b4d34 PH |
83 | }] |
84 | ||
85 | _FORMATS = { | |
86 | 's': {'width': 256, 'height': 144, 'quality': 1}, | |
87 | 'm': {'width': 512, 'height': 288, 'quality': 2}, | |
88 | 'l': {'width': 960, 'height': 544, 'quality': 3}, | |
89 | } | |
0e3ae924 | 90 | |
91 | def _real_extract(self, url): | |
122c2f87 PH |
92 | video_id = self._match_id(url) |
93 | display_id = video_id.lstrip('-') | |
0e3ae924 | 94 | webpage = self._download_webpage(url, display_id) |
95 | ||
045c4884 PH |
96 | player_url = self._html_search_meta( |
97 | 'twitter:player', webpage, 'player URL', default=None) | |
98 | if player_url: | |
99 | playerpage = self._download_webpage( | |
100 | player_url, display_id, 'Downloading player page') | |
0e3ae924 | 101 | |
045c4884 PH |
102 | medias = re.findall( |
103 | r'"(http://media.+?)", type:"video/(.+?)", quality:"(.+?)"', | |
104 | playerpage) | |
105 | formats = [] | |
106 | for url, ext, res in medias: | |
107 | f = { | |
108 | 'format_id': res + '_' + ext, | |
109 | 'url': url, | |
110 | 'ext': ext, | |
111 | } | |
112 | f.update(self._FORMATS.get(res, {})) | |
113 | formats.append(f) | |
114 | thumbnail_fn = re.findall(r'"(/multimedia/.+?\.jpg)"', playerpage)[-1] | |
115 | title = self._og_search_title(webpage).strip() | |
116 | description = self._og_search_description(webpage).strip() | |
117 | else: | |
118 | download_text = self._search_regex( | |
119 | r'(?s)<p>Wir bieten dieses Video in folgenden Formaten zum Download an:</p>\s*<div class="controls">(.*?)</div>\s*<p>', | |
120 | webpage, 'download links') | |
121 | links = re.finditer( | |
122 | r'<div class="button" title="(?P<title>[^"]*)"><a href="(?P<url>[^"]+)">(?P<name>.+?)</a></div>', | |
6591fdf5 | 123 | download_text) |
045c4884 PH |
124 | formats = [] |
125 | for l in links: | |
126 | format_id = self._search_regex( | |
127 | r'.*/[^/.]+\.([^/]+)\.[^/.]+', l.group('url'), 'format ID') | |
128 | format = { | |
129 | 'format_id': format_id, | |
130 | 'url': l.group('url'), | |
131 | 'format_name': l.group('name'), | |
132 | } | |
133 | m = re.match( | |
134 | r'''(?x) | |
135 | Video:\s*(?P<vcodec>[a-zA-Z0-9/._-]+)\s*&\#10; | |
136 | (?P<width>[0-9]+)x(?P<height>[0-9]+)px&\#10; | |
137 | (?P<vbr>[0-9]+)kbps&\#10; | |
138 | Audio:\s*(?P<abr>[0-9]+)kbps,\s*(?P<audio_desc>[A-Za-z\.0-9]+)&\#10; | |
139 | Größe:\s*(?P<filesize_approx>[0-9.,]+\s+[a-zA-Z]*B)''', | |
140 | l.group('title')) | |
141 | if m: | |
142 | format.update({ | |
143 | 'format_note': m.group('audio_desc'), | |
144 | 'vcodec': m.group('vcodec'), | |
145 | 'width': int(m.group('width')), | |
146 | 'height': int(m.group('height')), | |
147 | 'abr': int(m.group('abr')), | |
148 | 'vbr': int(m.group('vbr')), | |
149 | 'filesize_approx': parse_filesize(m.group('filesize_approx')), | |
150 | }) | |
151 | formats.append(format) | |
152 | thumbnail_fn = self._search_regex( | |
153 | r'(?s)<img alt="Sendungsbild".*?src="([^"]+)"', | |
154 | webpage, 'thumbnail', fatal=False) | |
e89d7e30 RH |
155 | # there are some videos without description |
156 | description = "" | |
726adc43 RH |
157 | description = self._html_search_regex( |
158 | r'(?s)<p class="teasertext">(.*?)</p>', | |
159 | webpage, 'description', fatal=False, default=None) | |
045c4884 PH |
160 | title = self._html_search_regex( |
161 | r'<span class="headline".*?>(.*?)</span>', webpage, 'title') | |
0e3ae924 | 162 | |
163 | self._sort_formats(formats) | |
045c4884 | 164 | thumbnail = 'http://www.tagesschau.de' + thumbnail_fn |
0e3ae924 | 165 | |
166 | return { | |
167 | 'id': display_id, | |
045c4884 PH |
168 | 'title': title, |
169 | 'thumbnail': thumbnail, | |
0e3ae924 | 170 | 'formats': formats, |
045c4884 | 171 | 'description': description, |
0e3ae924 | 172 | } |