[rtl2] Add new extractor
[youtube-dl] / youtube_dl / extractor / rtl2.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import json
6
7 from .common import InfoExtractor
8 from ..utils import (
9     ExtractorError,
10     clean_html,
11     unified_strdate,
12     int_or_none,
13 )
14
15
16 class RTL2IE(InfoExtractor):
17     """Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW"""
18     _VALID_URL = r'http?://(?P<url>(?P<domain>(www\.)?rtl2\.de)/.*/(?P<video_id>.*))'
19     _TEST = {
20         'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
21         'md5': 'dsadasdada',
22         'info_dict': {
23             'id': 'folge-203-0',
24             'ext': 'f4v',
25             'title': 'GRIP sucht den Sommerk\xf6nig',
26             'description' : 'Matthias, Det und Helge treten gegeneinander an.'
27             # TODO more properties, either as:
28             # * A value
29             # * MD5 checksum; start the string with md5:
30             # * A regular expression; start the string with re:
31             # * Any Python type (for example int or float)
32         },
33         #'params': {
34                 # rtmp download
35         #       'skip_download': True,
36         #},
37     }
38
39     def _real_extract(self, url):
40         mobj = re.match(self._VALID_URL, url)
41         video_page_url = 'http://%s/' % mobj.group('domain')
42         video_id = mobj.group('video_id')
43         
44         webpage = self._download_webpage('http://' + mobj.group('url'), video_id)
45
46         vico_id = self._html_search_regex(r'vico_id: ([0-9]+)', webpage, '%s');
47         vivi_id = self._html_search_regex(r'vivi_id: ([0-9]+)', webpage, '%s');
48
49         info_url = 'http://www.rtl2.de/video/php/get_video.php?vico_id=' + vico_id + '&vivi_id=' + vivi_id
50         webpage = self._download_webpage(info_url, '')
51
52         video_info = json.loads(webpage.decode("latin1"))
53         print video_info
54
55
56         #self._download_webpage('http://cp108781.edgefcs.net/crossdomain.xml', '')
57
58         download_url = video_info["video"]["streamurl"] # self._html_search_regex(r'streamurl\":\"(.*?)\"', webpage, '%s');
59         title = video_info["video"]["titel"] # self._html_search_regex(r'titel\":\"(.*?)\"', webpage, '%s');
60         description = video_info["video"]["beschreibung"] # self._html_search_regex(r'beschreibung\":\"(.*?)\"', webpage, '%s');
61         #ext = self._html_search_regex(r'streamurl\":\".*?(\..{2,4})\"', webpage, '%s');
62
63         thumbnail = video_info["video"]["image"]
64
65         download_url = download_url.replace("\\", "")
66
67         stream_url = 'mp4:' + self._html_search_regex(r'ondemand/(.*)', download_url, '%s');
68
69         #upload_date = self._html_search_regex(r'property=\"dc:date\".*?datatype=\"xsd:dateTime\".*?content=\"(.*?)\"', webpage, 'title')
70         #download_url += " -y " + stream_url
71         
72         #print stream_url
73         #print download_url
74         #print description
75         #print title
76         #print ext
77
78         formats = []
79
80         fmt = {
81             'url' : download_url,
82             #'app': 'ondemand?_fcs_vhost=cp108781.edgefcs.net',
83             'play_path': stream_url,
84             #'player_url': 'http://www.cbsnews.com/[[IMPORT]]/vidtech.cbsinteractive.com/player/3_3_0/CBSI_PLAYER_HD.swf',
85             #'page_url': 'http://www.cbsnews.com',
86             #'ext': ext,        
87         }
88
89         formats.append(fmt)
90
91
92         return {
93             'id': video_id,
94             'title': title,
95             'thumbnail' : thumbnail,
96             'description' : description,
97             'formats': formats,
98         }