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