76a9704fd6481bede2c9eb2834c5b6f4ab34b11f
[youtube-dl] / youtube_dl / extractor / rtlnow.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     parse_duration,
12     int_or_none,
13 )
14
15
16 class RTLnowIE(InfoExtractor):
17     """Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW"""
18     _VALID_URL = r'''(?x)
19                         (?:https?://)?
20                         (?P<url>
21                             (?P<domain>
22                                 rtl-now\.rtl\.de|
23                                 rtl2now\.rtl2\.de|
24                                 (?:www\.)?voxnow\.de|
25                                 (?:www\.)?rtlnitronow\.de|
26                                 (?:www\.)?superrtlnow\.de|
27                                 (?:www\.)?n-tvnow\.de)
28                             /+[a-zA-Z0-9-]+/[a-zA-Z0-9-]+\.php\?
29                             (?:container_id|film_id)=(?P<video_id>[0-9]+)&
30                             player=1(?:&season=[0-9]+)?(?:&.*)?
31                         )'''
32
33     _TESTS = [
34         {
35             'url': 'http://rtl-now.rtl.de/ahornallee/folge-1.php?film_id=90419&player=1&season=1',
36             'info_dict': {
37                 'id': '90419',
38                 'ext': 'flv',
39                 'title': 'Ahornallee - Folge 1 - Der Einzug',
40                 'description': 'md5:ce843b6b5901d9a7f7d04d1bbcdb12de',
41                 'upload_date': '20070416',
42                 'duration': 1685,
43             },
44             'params': {
45                 'skip_download': True,
46             },
47             'skip': 'Only works from Germany',
48         },
49         {
50             'url': 'http://rtl2now.rtl2.de/aerger-im-revier/episode-15-teil-1.php?film_id=69756&player=1&season=2&index=5',
51             'info_dict': {
52                 'id': '69756',
53                 'ext': 'flv',
54                 'title': 'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit u.a.',
55                 'description': 'md5:3fb247005ed21a935ffc82b7dfa70cf0',
56                 'thumbnail': 'http://autoimg.static-fra.de/rtl2now/219850/1500x1500/image2.jpg',
57                 'upload_date': '20120519',
58                 'duration': 1245,
59             },
60             'params': {
61                 'skip_download': True,
62             },
63             'skip': 'Only works from Germany',
64         },
65         {
66             'url': 'http://www.voxnow.de/voxtours/suedafrika-reporter-ii.php?film_id=13883&player=1&season=17',
67             'info_dict': {
68                 'id': '13883',
69                 'ext': 'flv',
70                 'title': 'Voxtours - Südafrika-Reporter II',
71                 'description': 'md5:de7f8d56be6fd4fed10f10f57786db00',
72                 'upload_date': '20090627',
73                 'duration': 1800,
74             },
75             'params': {
76                 'skip_download': True,
77             },
78         },
79         {
80             'url': 'http://superrtlnow.de/medicopter-117/angst.php?film_id=99205&player=1',
81             'info_dict': {
82                 'id': '99205',
83                 'ext': 'flv',
84                 'title': 'Medicopter 117 - Angst!',
85                 'description': 'md5:895b1df01639b5f61a04fc305a5cb94d',
86                 'thumbnail': 'http://autoimg.static-fra.de/superrtlnow/287529/1500x1500/image2.jpg',
87                 'upload_date': '20080928',
88                 'duration': 2691,
89             },
90             'params': {
91                 'skip_download': True,
92             },
93         },
94         {
95             'url': 'http://www.n-tvnow.de/deluxe-alles-was-spass-macht/thema-ua-luxushotel-fuer-vierbeiner.php?container_id=153819&player=1&season=0',
96             'info_dict': {
97                 'id': '153819',
98                 'ext': 'flv',
99                 'title': 'Deluxe - Alles was Spaß macht - Thema u.a.: Luxushotel für Vierbeiner',
100                 'description': 'md5:c3705e1bb32e1a5b2bcd634fc065c631',
101                 'thumbnail': 'http://autoimg.static-fra.de/ntvnow/383157/1500x1500/image2.jpg',
102                 'upload_date': '20140221',
103                 'duration': 2429,
104             },
105             'skip': 'Only works from Germany',
106         },
107     ]
108
109     def _real_extract(self, url):
110         mobj = re.match(self._VALID_URL, url)
111         video_page_url = 'http://%s/' % mobj.group('domain')
112         video_id = mobj.group('video_id')
113
114         webpage = self._download_webpage('http://' + mobj.group('url'), video_id)
115
116         mobj = re.search(r'(?s)<div style="margin-left: 20px; font-size: 13px;">(.*?)<div id="playerteaser">', webpage)
117         if mobj:
118             raise ExtractorError(clean_html(mobj.group(1)), expected=True)
119
120         title = self._og_search_title(webpage)
121         description = self._og_search_description(webpage)
122         thumbnail = self._og_search_thumbnail(webpage, default=None)
123
124         upload_date = unified_strdate(self._html_search_meta('uploadDate', webpage, 'upload date'))
125
126         playerdata_url = self._html_search_regex(
127             r"'playerdata': '(?P<playerdata_url>[^']+)'", webpage, 'playerdata_url')
128
129         playerdata = self._download_xml(playerdata_url, video_id, 'Downloading player data XML')
130
131         videoinfo = playerdata.find('./playlist/videoinfo')
132         duration = parse_duration(videoinfo.find('duration').text)
133
134         formats = []
135         for filename in videoinfo.findall('filename'):
136             mobj = re.search(r'(?P<url>rtmpe://(?:[^/]+/){2})(?P<play_path>.+)', filename.text)
137             if mobj:
138                 fmt = {
139                     'url': mobj.group('url'),
140                     'play_path': 'mp4:' + mobj.group('play_path'),
141                     'page_url': video_page_url,
142                     'player_url': video_page_url + 'includes/vodplayer.swf',
143                 }
144             else:
145                 fmt = {
146                     'url': filename.text,
147                 }
148             fmt.update({
149                 'width': int_or_none(filename.get('width')),
150                 'height': int_or_none(filename.get('height')),
151                 'vbr': int_or_none(filename.get('bitrate')),
152                 'ext': 'flv',
153             })
154             formats.append(fmt)
155
156         return {
157             'id': video_id,
158             'title': title,
159             'description': description,
160             'thumbnail': thumbnail,
161             'upload_date': upload_date,
162             'duration': duration,
163             'formats': formats,
164         }