]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/rtl2.py
[cleanup] Use `_html_extract_title`
[yt-dlp.git] / yt_dlp / extractor / rtl2.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
8 from ..compat import (
9 compat_b64decode,
10 compat_str,
11 )
12 from ..utils import (
13 ExtractorError,
14 int_or_none,
15 strip_or_none,
16 )
17
18
19 class RTL2IE(InfoExtractor):
20 IE_NAME = 'rtl2'
21 _VALID_URL = r'https?://(?:www\.)?rtl2\.de/sendung/[^/]+/(?:video/(?P<vico_id>\d+)[^/]+/(?P<vivi_id>\d+)-|folge/)(?P<id>[^/?#]+)'
22 _TESTS = [{
23 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
24 'info_dict': {
25 'id': 'folge-203-0',
26 'ext': 'f4v',
27 'title': 'GRIP sucht den Sommerkönig',
28 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f'
29 },
30 'params': {
31 # rtmp download
32 'skip_download': True,
33 },
34 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
35 }, {
36 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
37 'info_dict': {
38 'id': 'anna-erwischt-alex',
39 'ext': 'mp4',
40 'title': 'Anna erwischt Alex!',
41 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.'
42 },
43 'params': {
44 # rtmp download
45 'skip_download': True,
46 },
47 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
48 }]
49
50 def _real_extract(self, url):
51 vico_id, vivi_id, display_id = self._match_valid_url(url).groups()
52 if not vico_id:
53 webpage = self._download_webpage(url, display_id)
54
55 mobj = re.search(
56 r'data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
57 webpage)
58 if mobj:
59 vico_id = mobj.group('vico_id')
60 vivi_id = mobj.group('vivi_id')
61 else:
62 vico_id = self._html_search_regex(
63 r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
64 vivi_id = self._html_search_regex(
65 r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
66
67 info = self._download_json(
68 'https://service.rtl2.de/api-player-vipo/video.php',
69 display_id, query={
70 'vico_id': vico_id,
71 'vivi_id': vivi_id,
72 })
73 video_info = info['video']
74 title = video_info['titel']
75
76 formats = []
77
78 rtmp_url = video_info.get('streamurl')
79 if rtmp_url:
80 rtmp_url = rtmp_url.replace('\\', '')
81 stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL')
82 rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0']
83
84 formats.append({
85 'format_id': 'rtmp',
86 'url': rtmp_url,
87 'play_path': stream_url,
88 'player_url': 'https://www.rtl2.de/sites/default/modules/rtl2/jwplayer/jwplayer-7.6.0/jwplayer.flash.swf',
89 'page_url': url,
90 'flash_version': 'LNX 11,2,202,429',
91 'rtmp_conn': rtmp_conn,
92 'no_resume': True,
93 'quality': 1,
94 })
95
96 m3u8_url = video_info.get('streamurl_hls')
97 if m3u8_url:
98 formats.extend(self._extract_akamai_formats(m3u8_url, display_id))
99
100 self._sort_formats(formats)
101
102 return {
103 'id': display_id,
104 'title': title,
105 'thumbnail': video_info.get('image'),
106 'description': video_info.get('beschreibung'),
107 'duration': int_or_none(video_info.get('duration')),
108 'formats': formats,
109 }
110
111
112 class RTL2YouBaseIE(InfoExtractor):
113 _BACKWERK_BASE_URL = 'https://p-you-backwerk.rtl2apps.de/'
114
115
116 class RTL2YouIE(RTL2YouBaseIE):
117 IE_NAME = 'rtl2:you'
118 _VALID_URL = r'http?://you\.rtl2\.de/(?:video/\d+/|youplayer/index\.html\?.*?\bvid=)(?P<id>\d+)'
119 _TESTS = [{
120 'url': 'http://you.rtl2.de/video/3002/15740/MJUNIK%20%E2%80%93%20Home%20of%20YOU/307-hirn-wo-bist-du',
121 'info_dict': {
122 'id': '15740',
123 'ext': 'mp4',
124 'title': 'MJUNIK – Home of YOU - #307 Hirn, wo bist du?!',
125 'description': 'md5:ddaa95c61b372b12b66e115b2772fe01',
126 'age_limit': 12,
127 },
128 }, {
129 'url': 'http://you.rtl2.de/youplayer/index.html?vid=15712',
130 'only_matching': True,
131 }]
132 _AES_KEY = b'\xe9W\xe4.<*\xb8\x1a\xd2\xb6\x92\xf3C\xd3\xefL\x1b\x03*\xbbbH\xc0\x03\xffo\xc2\xf2(\xaa\xaa!'
133 _GEO_COUNTRIES = ['DE']
134
135 def _real_extract(self, url):
136 video_id = self._match_id(url)
137
138 stream_data = self._download_json(
139 self._BACKWERK_BASE_URL + 'stream/video/' + video_id, video_id)
140
141 data, iv = compat_b64decode(stream_data['streamUrl']).decode().split(':')
142 stream_url = unpad_pkcs7(aes_cbc_decrypt_bytes(
143 compat_b64decode(data), self._AES_KEY, compat_b64decode(iv)))
144 if b'rtl2_you_video_not_found' in stream_url:
145 raise ExtractorError('video not found', expected=True)
146
147 formats = self._extract_m3u8_formats(stream_url.decode(), video_id, 'mp4', 'm3u8_native')
148 self._sort_formats(formats)
149
150 video_data = self._download_json(
151 self._BACKWERK_BASE_URL + 'video/' + video_id, video_id)
152
153 series = video_data.get('formatTitle')
154 title = episode = video_data.get('title') or series
155 if series and series != title:
156 title = '%s - %s' % (series, title)
157
158 return {
159 'id': video_id,
160 'title': title,
161 'formats': formats,
162 'description': strip_or_none(video_data.get('description')),
163 'thumbnail': video_data.get('image'),
164 'duration': int_or_none(stream_data.get('duration') or video_data.get('duration'), 1000),
165 'series': series,
166 'episode': episode,
167 'age_limit': int_or_none(video_data.get('minimumAge')),
168 }
169
170
171 class RTL2YouSeriesIE(RTL2YouBaseIE):
172 IE_NAME = 'rtl2:you:series'
173 _VALID_URL = r'http?://you\.rtl2\.de/videos/(?P<id>\d+)'
174 _TEST = {
175 'url': 'http://you.rtl2.de/videos/115/dragon-ball',
176 'info_dict': {
177 'id': '115',
178 },
179 'playlist_mincount': 5,
180 }
181
182 def _real_extract(self, url):
183 series_id = self._match_id(url)
184 stream_data = self._download_json(
185 self._BACKWERK_BASE_URL + 'videos',
186 series_id, query={
187 'formatId': series_id,
188 'limit': 1000000000,
189 })
190
191 entries = []
192 for video in stream_data.get('videos', []):
193 video_id = compat_str(video['videoId'])
194 if not video_id:
195 continue
196 entries.append(self.url_result(
197 'http://you.rtl2.de/video/%s/%s' % (series_id, video_id),
198 'RTL2You', video_id))
199 return self.playlist_result(entries, series_id)