]>
Commit | Line | Data |
---|---|---|
b8223203 | 1 | # coding: utf-8 |
8f4b58d7 PH |
2 | from __future__ import unicode_literals |
3 | ||
b8223203 YCH |
4 | import re |
5 | ||
8f4b58d7 | 6 | from .common import InfoExtractor |
163e8369 | 7 | from ..compat import compat_urlparse |
8f4b58d7 PH |
8 | from ..utils import ( |
9 | int_or_none, | |
10 | js_to_json, | |
11 | parse_duration, | |
12 | ) | |
13 | ||
14 | ||
15 | class NTVDeIE(InfoExtractor): | |
16 | IE_NAME = 'n-tv.de' | |
17 | _VALID_URL = r'https?://(?:www\.)?n-tv\.de/mediathek/videos/[^/?#]+/[^/?#]+-article(?P<id>.+)\.html' | |
18 | ||
19 | _TESTS = [{ | |
20 | 'url': 'http://www.n-tv.de/mediathek/videos/panorama/Schnee-und-Glaette-fuehren-zu-zahlreichen-Unfaellen-und-Staus-article14438086.html', | |
7a7bd19c | 21 | 'md5': '6ef2514d4b1e8e03ca24b49e2f167153', |
8f4b58d7 PH |
22 | 'info_dict': { |
23 | 'id': '14438086', | |
24 | 'ext': 'mp4', | |
ec85ded8 | 25 | 'thumbnail': r're:^https?://.*\.jpg$', |
8f4b58d7 PH |
26 | 'title': 'Schnee und Glätte führen zu zahlreichen Unfällen und Staus', |
27 | 'alt_title': 'Winterchaos auf deutschen Straßen', | |
28 | 'description': 'Schnee und Glätte sorgen deutschlandweit für einen chaotischen Start in die Woche: Auf den Straßen kommt es zu kilometerlangen Staus und Dutzenden Glätteunfällen. In Düsseldorf und München wirbelt der Schnee zudem den Flugplan durcheinander. Dutzende Flüge landen zu spät, einige fallen ganz aus.', | |
29 | 'duration': 4020, | |
30 | 'timestamp': 1422892797, | |
31 | 'upload_date': '20150202', | |
32 | }, | |
33 | }] | |
34 | ||
35 | def _real_extract(self, url): | |
36 | video_id = self._match_id(url) | |
37 | webpage = self._download_webpage(url, video_id) | |
38 | ||
39 | info = self._parse_json(self._search_regex( | |
6b559c2f | 40 | r'(?s)ntv\.pageInfo\.article\s*=\s*(\{.*?\});', webpage, 'info'), |
8f4b58d7 PH |
41 | video_id, transform_source=js_to_json) |
42 | timestamp = int_or_none(info.get('publishedDateAsUnixTimeStamp')) | |
43 | vdata = self._parse_json(self._search_regex( | |
44 | r'(?s)\$\(\s*"\#player"\s*\)\s*\.data\(\s*"player",\s*(\{.*?\})\);', | |
b8223203 YCH |
45 | webpage, 'player data'), video_id, |
46 | transform_source=lambda s: js_to_json(re.sub(r'advertising:\s*{[^}]+},', '', s))) | |
8f4b58d7 | 47 | duration = parse_duration(vdata.get('duration')) |
163e8369 S |
48 | |
49 | formats = [] | |
50 | if vdata.get('video'): | |
51 | formats.append({ | |
52 | 'format_id': 'flash', | |
53 | 'url': 'rtmp://fms.n-tv.de/%s' % vdata['video'], | |
54 | }) | |
55 | if vdata.get('videoMp4'): | |
56 | formats.append({ | |
57 | 'format_id': 'mobile', | |
58 | 'url': compat_urlparse.urljoin('http://video.n-tv.de', vdata['videoMp4']), | |
59 | 'tbr': 400, # estimation | |
60 | }) | |
61 | if vdata.get('videoM3u8'): | |
62 | m3u8_url = compat_urlparse.urljoin('http://video.n-tv.de', vdata['videoM3u8']) | |
63 | formats.extend(self._extract_m3u8_formats( | |
64 | m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native', | |
65 | preference=0, m3u8_id='hls', fatal=False)) | |
8f4b58d7 PH |
66 | self._sort_formats(formats) |
67 | ||
68 | return { | |
69 | 'id': video_id, | |
70 | 'title': info['headline'], | |
71 | 'description': info.get('intro'), | |
72 | 'alt_title': info.get('kicker'), | |
73 | 'timestamp': timestamp, | |
74 | 'thumbnail': vdata.get('html5VideoPoster'), | |
75 | 'duration': duration, | |
76 | 'formats': formats, | |
77 | } |