]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ntvde.py
Merge pull request #8061 from dstftw/introduce-chapter-and-series-fields
[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
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',
22 'thumbnail': 're:^https?://.*\.jpg$',
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(
37 r'(?s)ntv.pageInfo.article =\s(\{.*?\});', webpage, 'info'),
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*(\{.*?\})\);',
42 webpage, 'player data'),
43 video_id, transform_source=js_to_json)
44 duration = parse_duration(vdata.get('duration'))
45 formats = [{
46 'format_id': 'flash',
47 'url': 'rtmp://fms.n-tv.de/' + vdata['video'],
48 }, {
7a7bd19c 49 'format_id': 'mobile',
8f4b58d7 50 'url': 'http://video.n-tv.de' + vdata['videoMp4'],
7a7bd19c 51 'tbr': 400, # estimation
8f4b58d7
PH
52 }]
53 m3u8_url = 'http://video.n-tv.de' + vdata['videoM3u8']
7a7bd19c
PH
54 formats.extend(self._extract_m3u8_formats(
55 m3u8_url, video_id, ext='mp4',
56 entry_protocol='m3u8_native', preference=0))
8f4b58d7
PH
57 self._sort_formats(formats)
58
59 return {
60 'id': video_id,
61 'title': info['headline'],
62 'description': info.get('intro'),
63 'alt_title': info.get('kicker'),
64 'timestamp': timestamp,
65 'thumbnail': vdata.get('html5VideoPoster'),
66 'duration': duration,
67 'formats': formats,
68 }