[rtlnow] Modernize and add f4m support
[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/top-gear/episode-1-2013-01-01-00-00-00.php?film_id=124903&player=1&season=10',
96             'info_dict': {
97                 'id': '124903',
98                 'ext': 'flv',
99                 'title': 'Top Gear vom 01.01.2013',
100                 'description': 'Episode 1',
101                 'upload_date': '20130101',
102             },
103             'params': {
104                 'skip_download': True,
105             },
106             'skip': 'Only works from Germany',
107         },
108     ]
109
110     def _real_extract(self, url):
111         mobj = re.match(self._VALID_URL, url)
112         video_page_url = 'http://%s/' % mobj.group('domain')
113         video_id = mobj.group('video_id')
114
115         webpage = self._download_webpage('http://' + mobj.group('url'), video_id)
116
117         mobj = re.search(r'(?s)<div style="margin-left: 20px; font-size: 13px;">(.*?)<div id="playerteaser">', webpage)
118         if mobj:
119             raise ExtractorError(clean_html(mobj.group(1)), expected=True)
120
121         title = self._og_search_title(webpage)
122         description = self._og_search_description(webpage)
123         thumbnail = self._og_search_thumbnail(webpage, default=None)
124
125         upload_date = unified_strdate(self._html_search_meta('uploadDate', webpage, 'upload date'))
126
127         playerdata_url = self._html_search_regex(
128             r"'playerdata': '(?P<playerdata_url>[^']+)'", webpage, 'playerdata_url')
129
130         playerdata = self._download_xml(playerdata_url, video_id, 'Downloading player data XML')
131
132         videoinfo = playerdata.find('./playlist/videoinfo')
133         duration = parse_duration(videoinfo.find('duration').text)
134
135         formats = []
136         for filename in videoinfo.findall('filename'):
137             mobj = re.search(r'(?P<url>rtmpe://(?:[^/]+/){2})(?P<play_path>.+)', filename.text)
138             if mobj:
139                 fmt = {
140                     'url': mobj.group('url'),
141                     'play_path': 'mp4:' + mobj.group('play_path'),
142                     'page_url': video_page_url,
143                     'player_url': video_page_url + 'includes/vodplayer.swf',
144                 }
145             else:
146                 fmt = {
147                     'url': filename.text,
148                 }
149             fmt.update({
150                 'width': int_or_none(filename.get('width')),
151                 'height': int_or_none(filename.get('height')),
152                 'vbr': int_or_none(filename.get('bitrate')),
153                 'ext': 'flv',
154             })
155             formats.append(fmt)
156
157         return {
158             'id': video_id,
159             'title': title,
160             'description': description,
161             'thumbnail': thumbnail,
162             'upload_date': upload_date,
163             'duration': duration,
164             'formats': formats,
165         }