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