2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..aes import aes_cbc_decrypt
22 class RTL2IE(InfoExtractor):
24 _VALID_URL = r'http?://(?:www\.)?rtl2\.de/[^?#]*?/(?P<id>[^?#/]*?)(?:$|/(?:$|[?#]))'
26 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
30 'title': 'GRIP sucht den Sommerkönig',
31 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f'
35 'skip_download': True,
38 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
40 'id': '21040-anna-erwischt-alex',
42 'title': 'Anna erwischt Alex!',
43 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.'
47 'skip_download': True,
51 def _real_extract(self, url):
52 # Some rtl2 urls have no slash at the end, so append it.
53 if not url.endswith('/'):
56 video_id = self._match_id(url)
57 webpage = self._download_webpage(url, video_id)
60 r'<div[^>]+data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
63 vico_id = mobj.group('vico_id')
64 vivi_id = mobj.group('vivi_id')
66 vico_id = self._html_search_regex(
67 r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
68 vivi_id = self._html_search_regex(
69 r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
71 info = self._download_json(
72 'http://www.rtl2.de/sites/default/modules/rtl2/mediathek/php/get_video_jw.php',
77 video_info = info['video']
78 title = video_info['titel']
82 rtmp_url = video_info.get('streamurl')
84 rtmp_url = rtmp_url.replace('\\', '')
85 stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL')
86 rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0']
91 'play_path': stream_url,
92 'player_url': 'http://www.rtl2.de/flashplayer/vipo_player.swf',
94 'flash_version': 'LNX 11,2,202,429',
95 'rtmp_conn': rtmp_conn,
100 m3u8_url = video_info.get('streamurl_hls')
102 formats.extend(self._extract_akamai_formats(m3u8_url, video_id))
104 self._sort_formats(formats)
109 'thumbnail': video_info.get('image'),
110 'description': video_info.get('beschreibung'),
111 'duration': int_or_none(video_info.get('duration')),
116 class RTL2YouBaseIE(InfoExtractor):
117 _BACKWERK_BASE_URL = 'https://p-you-backwerk.rtl2apps.de/'
120 class RTL2YouIE(RTL2YouBaseIE):
122 _VALID_URL = r'http?://you\.rtl2\.de/(?:video/\d+/|youplayer/index\.html\?.*?\bvid=)(?P<id>\d+)'
124 'url': 'http://you.rtl2.de/video/3002/15740/MJUNIK%20%E2%80%93%20Home%20of%20YOU/307-hirn-wo-bist-du',
128 'title': 'MJUNIK – Home of YOU - #307 Hirn, wo bist du?!',
129 'description': 'md5:ddaa95c61b372b12b66e115b2772fe01',
133 'url': 'http://you.rtl2.de/youplayer/index.html?vid=15712',
134 'only_matching': True,
136 _AES_KEY = b'\xe9W\xe4.<*\xb8\x1a\xd2\xb6\x92\xf3C\xd3\xefL\x1b\x03*\xbbbH\xc0\x03\xffo\xc2\xf2(\xaa\xaa!'
137 _GEO_COUNTRIES = ['DE']
139 def _real_extract(self, url):
140 video_id = self._match_id(url)
142 stream_data = self._download_json(
143 self._BACKWERK_BASE_URL + 'stream/video/' + video_id, video_id)
145 data, iv = compat_b64decode(stream_data['streamUrl']).decode().split(':')
146 stream_url = intlist_to_bytes(aes_cbc_decrypt(
147 bytes_to_intlist(compat_b64decode(data)),
148 bytes_to_intlist(self._AES_KEY),
149 bytes_to_intlist(compat_b64decode(iv))
151 if b'rtl2_you_video_not_found' in stream_url:
152 raise ExtractorError('video not found', expected=True)
154 formats = self._extract_m3u8_formats(
155 stream_url[:-compat_ord(stream_url[-1])].decode(),
156 video_id, 'mp4', 'm3u8_native')
157 self._sort_formats(formats)
159 video_data = self._download_json(
160 self._BACKWERK_BASE_URL + 'video/' + video_id, video_id)
162 series = video_data.get('formatTitle')
163 title = episode = video_data.get('title') or series
164 if series and series != title:
165 title = '%s - %s' % (series, title)
171 'description': strip_or_none(video_data.get('description')),
172 'thumbnail': video_data.get('image'),
173 'duration': int_or_none(stream_data.get('duration') or video_data.get('duration'), 1000),
176 'age_limit': int_or_none(video_data.get('minimumAge')),
180 class RTL2YouSeriesIE(RTL2YouBaseIE):
181 IE_NAME = 'rtl2:you:series'
182 _VALID_URL = r'http?://you\.rtl2\.de/videos/(?P<id>\d+)'
184 'url': 'http://you.rtl2.de/videos/115/dragon-ball',
188 'playlist_mincount': 5,
191 def _real_extract(self, url):
192 series_id = self._match_id(url)
193 stream_data = self._download_json(
194 self._BACKWERK_BASE_URL + 'videos',
196 'formatId': series_id,
201 for video in stream_data.get('videos', []):
202 video_id = compat_str(video['videoId'])
205 entries.append(self.url_result(
206 'http://you.rtl2.de/video/%s/%s' % (series_id, video_id),
207 'RTL2You', video_id))
208 return self.playlist_result(entries, series_id)