]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rtl2.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / rtl2.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import int_or_none
5
6
7 class RTL2IE(InfoExtractor):
8 IE_NAME = 'rtl2'
9 _VALID_URL = r'https?://(?:www\.)?rtl2\.de/sendung/[^/]+/(?:video/(?P<vico_id>\d+)[^/]+/(?P<vivi_id>\d+)-|folge/)(?P<id>[^/?#]+)'
10 _TESTS = [{
11 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
12 'info_dict': {
13 'id': 'folge-203-0',
14 'ext': 'f4v',
15 'title': 'GRIP sucht den Sommerkönig',
16 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f'
17 },
18 'params': {
19 # rtmp download
20 'skip_download': True,
21 },
22 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
23 }, {
24 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
25 'info_dict': {
26 'id': 'anna-erwischt-alex',
27 'ext': 'mp4',
28 'title': 'Anna erwischt Alex!',
29 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.'
30 },
31 'params': {
32 # rtmp download
33 'skip_download': True,
34 },
35 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
36 }]
37
38 def _real_extract(self, url):
39 vico_id, vivi_id, display_id = self._match_valid_url(url).groups()
40 if not vico_id:
41 webpage = self._download_webpage(url, display_id)
42
43 mobj = re.search(
44 r'data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
45 webpage)
46 if mobj:
47 vico_id = mobj.group('vico_id')
48 vivi_id = mobj.group('vivi_id')
49 else:
50 vico_id = self._html_search_regex(
51 r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
52 vivi_id = self._html_search_regex(
53 r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
54
55 info = self._download_json(
56 'https://service.rtl2.de/api-player-vipo/video.php',
57 display_id, query={
58 'vico_id': vico_id,
59 'vivi_id': vivi_id,
60 })
61 video_info = info['video']
62 title = video_info['titel']
63
64 formats = []
65
66 rtmp_url = video_info.get('streamurl')
67 if rtmp_url:
68 rtmp_url = rtmp_url.replace('\\', '')
69 stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL')
70 rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0']
71
72 formats.append({
73 'format_id': 'rtmp',
74 'url': rtmp_url,
75 'play_path': stream_url,
76 'player_url': 'https://www.rtl2.de/sites/default/modules/rtl2/jwplayer/jwplayer-7.6.0/jwplayer.flash.swf',
77 'page_url': url,
78 'flash_version': 'LNX 11,2,202,429',
79 'rtmp_conn': rtmp_conn,
80 'no_resume': True,
81 'quality': 1,
82 })
83
84 m3u8_url = video_info.get('streamurl_hls')
85 if m3u8_url:
86 formats.extend(self._extract_akamai_formats(m3u8_url, display_id))
87
88 return {
89 'id': display_id,
90 'title': title,
91 'thumbnail': video_info.get('image'),
92 'description': video_info.get('beschreibung'),
93 'duration': int_or_none(video_info.get('duration')),
94 'formats': formats,
95 }