]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtl2.py
Merge tag 'upstream/2017.02.07'
[youtubedl] / youtube_dl / 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 ..utils import int_or_none
8
9
10 class RTL2IE(InfoExtractor):
11 _VALID_URL = r'http?://(?:www\.)?rtl2\.de/[^?#]*?/(?P<id>[^?#/]*?)(?:$|/(?:$|[?#]))'
12 _TESTS = [{
13 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
14 'info_dict': {
15 'id': 'folge-203-0',
16 'ext': 'f4v',
17 'title': 'GRIP sucht den Sommerkönig',
18 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f'
19 },
20 'params': {
21 # rtmp download
22 'skip_download': True,
23 },
24 }, {
25 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
26 'info_dict': {
27 'id': '21040-anna-erwischt-alex',
28 'ext': 'mp4',
29 'title': 'Anna erwischt Alex!',
30 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.'
31 },
32 'params': {
33 # rtmp download
34 'skip_download': True,
35 },
36 }]
37
38 def _real_extract(self, url):
39 # Some rtl2 urls have no slash at the end, so append it.
40 if not url.endswith('/'):
41 url += '/'
42
43 video_id = self._match_id(url)
44 webpage = self._download_webpage(url, video_id)
45
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')
57
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 })
64 video_info = info['video']
65 title = video_info['titel']
66
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))
90
91 self._sort_formats(formats)
92
93 return {
94 'id': video_id,
95 'title': title,
96 'thumbnail': video_info.get('image'),
97 'description': video_info.get('beschreibung'),
98 'duration': int_or_none(video_info.get('duration')),
99 'formats': formats,
100 }