]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
7906d199 DD |
2 | from __future__ import unicode_literals |
3 | ||
5e1a5ac8 | 4 | import re |
9c5b5f21 | 5 | |
7906d199 | 6 | from .common import InfoExtractor |
9c5b5f21 | 7 | from ..utils import int_or_none |
7906d199 DD |
8 | |
9 | ||
10 | class RTL2IE(InfoExtractor): | |
3dee7826 | 11 | _VALID_URL = r'http?://(?:www\.)?rtl2\.de/[^?#]*?/(?P<id>[^?#/]*?)(?:$|/(?:$|[?#]))' |
7906d199 | 12 | _TESTS = [{ |
3dee7826 | 13 | 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0', |
3dee7826 PH |
14 | 'info_dict': { |
15 | 'id': 'folge-203-0', | |
16 | 'ext': 'f4v', | |
17 | 'title': 'GRIP sucht den Sommerkönig', | |
9c5b5f21 | 18 | 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f' |
7906d199 | 19 | }, |
4932a817 YCH |
20 | 'params': { |
21 | # rtmp download | |
22 | 'skip_download': True, | |
23 | }, | |
3dee7826 PH |
24 | }, { |
25 | 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/', | |
3dee7826 PH |
26 | 'info_dict': { |
27 | 'id': '21040-anna-erwischt-alex', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'Anna erwischt Alex!', | |
9c5b5f21 | 30 | 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.' |
7906d199 | 31 | }, |
5e1a5ac8 YCH |
32 | 'params': { |
33 | # rtmp download | |
34 | 'skip_download': True, | |
35 | }, | |
3dee7826 | 36 | }] |
7906d199 DD |
37 | |
38 | def _real_extract(self, url): | |
3dee7826 PH |
39 | # Some rtl2 urls have no slash at the end, so append it. |
40 | if not url.endswith('/'): | |
fe41ddbb | 41 | url += '/' |
7906d199 | 42 | |
3dee7826 | 43 | video_id = self._match_id(url) |
fe41ddbb DD |
44 | webpage = self._download_webpage(url, video_id) |
45 | ||
5e1a5ac8 YCH |
46 | mobj = re.search( |
47 | r'<div[^>]+data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"', | |
48 | webpage) | |
49 | if mobj: | |
50 | vico_id = mobj.group('vico_id') | |
51 | vivi_id = mobj.group('vivi_id') | |
52 | else: | |
53 | vico_id = self._html_search_regex( | |
54 | r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id') | |
55 | vivi_id = self._html_search_regex( | |
56 | r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id') | |
7906d199 | 57 | |
9c5b5f21 RA |
58 | info = self._download_json( |
59 | 'http://www.rtl2.de/sites/default/modules/rtl2/mediathek/php/get_video_jw.php', | |
60 | video_id, query={ | |
61 | 'vico_id': vico_id, | |
62 | 'vivi_id': vivi_id, | |
63 | }) | |
3dee7826 PH |
64 | video_info = info['video'] |
65 | title = video_info['titel'] | |
7906d199 | 66 | |
9c5b5f21 RA |
67 | formats = [] |
68 | ||
69 | rtmp_url = video_info.get('streamurl') | |
70 | if rtmp_url: | |
71 | rtmp_url = rtmp_url.replace('\\', '') | |
72 | stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL') | |
73 | rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0'] | |
74 | ||
75 | formats.append({ | |
76 | 'format_id': 'rtmp', | |
77 | 'url': rtmp_url, | |
78 | 'play_path': stream_url, | |
79 | 'player_url': 'http://www.rtl2.de/flashplayer/vipo_player.swf', | |
80 | 'page_url': url, | |
81 | 'flash_version': 'LNX 11,2,202,429', | |
82 | 'rtmp_conn': rtmp_conn, | |
83 | 'no_resume': True, | |
84 | 'preference': 1, | |
85 | }) | |
86 | ||
87 | m3u8_url = video_info.get('streamurl_hls') | |
88 | if m3u8_url: | |
89 | formats.extend(self._extract_akamai_formats(m3u8_url, video_id)) | |
7906d199 | 90 | |
3dee7826 | 91 | self._sort_formats(formats) |
7906d199 DD |
92 | |
93 | return { | |
94 | 'id': video_id, | |
95 | 'title': title, | |
9c5b5f21 RA |
96 | 'thumbnail': video_info.get('image'), |
97 | 'description': video_info.get('beschreibung'), | |
98 | 'duration': int_or_none(video_info.get('duration')), | |
7906d199 DD |
99 | 'formats': formats, |
100 | } |