]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/ntvde.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / ntvde.py
CommitLineData
b8223203
YCH
1import re
2
8f4b58d7 3from .common import InfoExtractor
163e8369 4from ..compat import compat_urlparse
8f4b58d7
PH
5from ..utils import (
6 int_or_none,
7 js_to_json,
8 parse_duration,
9)
10
11
12class NTVDeIE(InfoExtractor):
13 IE_NAME = 'n-tv.de'
14 _VALID_URL = r'https?://(?:www\.)?n-tv\.de/mediathek/videos/[^/?#]+/[^/?#]+-article(?P<id>.+)\.html'
15
16 _TESTS = [{
17 'url': 'http://www.n-tv.de/mediathek/videos/panorama/Schnee-und-Glaette-fuehren-zu-zahlreichen-Unfaellen-und-Staus-article14438086.html',
7a7bd19c 18 'md5': '6ef2514d4b1e8e03ca24b49e2f167153',
8f4b58d7
PH
19 'info_dict': {
20 'id': '14438086',
21 'ext': 'mp4',
ec85ded8 22 'thumbnail': r're:^https?://.*\.jpg$',
8f4b58d7
PH
23 'title': 'Schnee und Glätte führen zu zahlreichen Unfällen und Staus',
24 'alt_title': 'Winterchaos auf deutschen Straßen',
25 '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.',
26 'duration': 4020,
27 'timestamp': 1422892797,
28 'upload_date': '20150202',
29 },
30 }]
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34 webpage = self._download_webpage(url, video_id)
35
36 info = self._parse_json(self._search_regex(
6b559c2f 37 r'(?s)ntv\.pageInfo\.article\s*=\s*(\{.*?\});', webpage, 'info'),
8f4b58d7
PH
38 video_id, transform_source=js_to_json)
39 timestamp = int_or_none(info.get('publishedDateAsUnixTimeStamp'))
40 vdata = self._parse_json(self._search_regex(
41 r'(?s)\$\(\s*"\#player"\s*\)\s*\.data\(\s*"player",\s*(\{.*?\})\);',
b8223203
YCH
42 webpage, 'player data'), video_id,
43 transform_source=lambda s: js_to_json(re.sub(r'advertising:\s*{[^}]+},', '', s)))
8f4b58d7 44 duration = parse_duration(vdata.get('duration'))
163e8369
S
45
46 formats = []
47 if vdata.get('video'):
48 formats.append({
49 'format_id': 'flash',
50 'url': 'rtmp://fms.n-tv.de/%s' % vdata['video'],
51 })
52 if vdata.get('videoMp4'):
53 formats.append({
54 'format_id': 'mobile',
55 'url': compat_urlparse.urljoin('http://video.n-tv.de', vdata['videoMp4']),
56 'tbr': 400, # estimation
57 })
58 if vdata.get('videoM3u8'):
59 m3u8_url = compat_urlparse.urljoin('http://video.n-tv.de', vdata['videoM3u8'])
60 formats.extend(self._extract_m3u8_formats(
61 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
f983b875 62 quality=1, m3u8_id='hls', fatal=False))
8f4b58d7
PH
63
64 return {
65 'id': video_id,
66 'title': info['headline'],
67 'description': info.get('intro'),
68 'alt_title': info.get('kicker'),
69 'timestamp': timestamp,
70 'thumbnail': vdata.get('html5VideoPoster'),
71 'duration': duration,
72 'formats': formats,
73 }