Merge remote-tracking branch 'David-Development/rtl2.py'
[youtube-dl] / youtube_dl / extractor / rtl2.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     ExtractorError,
9     clean_html,
10     unified_strdate,
11     int_or_none,
12 )
13
14
15 class RTL2IE(InfoExtractor):
16     """Information Extractor for RTL2"""
17     _VALID_URL = r'http?://(?P<url>(?P<domain>(www\.)?rtl2\.de)/.*/(?P<video_id>.*))/'
18     _TESTS = [{
19             'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
20             'info_dict': {
21                 'id': 'folge-203-0',
22                 'ext': 'f4v',
23                 'title': 'GRIP sucht den Sommerkönig',
24                 'description' : 'Matthias, Det und Helge treten gegeneinander an.'
25             },
26             'params': {
27                 # rtmp download
28                 'skip_download': True,
29             },
30         },
31         {
32             'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
33             'info_dict': {
34                 'id': '21040-anna-erwischt-alex',
35                 'ext': 'mp4',
36                 'title': 'Anna erwischt Alex!',
37                 'description' : 'Anna ist Alex\' Tochter bei Köln 50667.'
38             },
39             'params': {
40                 # rtmp download
41                 'skip_download': True,
42             },
43         },
44     ]
45
46     def _real_extract(self, url):
47         
48         #Some rtl2 urls have no slash at the end, so append it.
49         if not url.endswith("/"):
50             url += '/'
51         
52         mobj = re.match(self._VALID_URL, url)
53         video_id = mobj.group('video_id')
54
55         webpage = self._download_webpage(url, video_id)
56
57         vico_id = self._html_search_regex(r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id not found');
58         vivi_id = self._html_search_regex(r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id not found');
59
60         info_url = 'http://www.rtl2.de/video/php/get_video.php?vico_id=' + vico_id + '&vivi_id=' + vivi_id
61         webpage = self._download_webpage(info_url, '')
62
63         video_info = self._download_json(info_url, video_id)
64
65         download_url = video_info["video"]["streamurl"]
66         title = video_info["video"]["titel"]
67         description = video_info["video"]["beschreibung"]
68
69         thumbnail = video_info["video"]["image"]
70
71         download_url = download_url.replace("\\", "")
72
73         stream_url = 'mp4:' + self._html_search_regex(r'ondemand/(.*)', download_url, '%s')
74         
75         #Debug output
76         #print('URL: '        + url)
77         #print('DL URL: '     + download_url)
78         #print('Stream URL: ' + stream_url)
79         #print('Title: '      + title)
80         #print('Description: '+ description)
81         #print('Video ID: '   + video_id)
82                 
83         formats = [{
84                 'url' : download_url,
85                 #'app': 'ondemand?_fcs_vhost=cp108781.edgefcs.net',
86                 'play_path': stream_url,
87                 'player_url': 'http://www.rtl2.de/flashplayer/vipo_player.swf',
88                 'page_url': url,
89                 'flash_version' : "LNX 11,2,202,429",
90                 'rtmp_conn' : ["S:connect", "O:1", "NS:pageUrl:" + url, "NB:fpad:0", "NN:videoFunction:1", "O:0"],
91                 'no_resume' : True,
92             }]
93
94         return {
95             'id': video_id,
96             'title': title,
97             'thumbnail' : thumbnail,
98             'description' : description,
99             'formats': formats,
100         }