]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/rtlnow.py
Imported Upstream version 2013.11.11
[youtubedl] / youtube_dl / extractor / rtlnow.py
1 # encoding: utf-8
2 import re
3
4 from .common import InfoExtractor
5 from ..utils import (
6 clean_html,
7 ExtractorError,
8 )
9
10 class RTLnowIE(InfoExtractor):
11 """Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW"""
12 _VALID_URL = r'(?:http://)?(?P<url>(?P<base_url>rtl-now\.rtl\.de/|rtl2now\.rtl2\.de/|(?:www\.)?voxnow\.de/|(?:www\.)?rtlnitronow\.de/|(?:www\.)?superrtlnow\.de/|(?:www\.)?n-tvnow\.de/)[a-zA-Z0-9-]+/[a-zA-Z0-9-]+\.php\?(?:container_id|film_id)=(?P<video_id>[0-9]+)&player=1(?:&season=[0-9]+)?(?:&.*)?)'
13 _TESTS = [{
14 u'url': u'http://rtl-now.rtl.de/ahornallee/folge-1.php?film_id=90419&player=1&season=1',
15 u'file': u'90419.flv',
16 u'info_dict': {
17 u'upload_date': u'20070416',
18 u'title': u'Ahornallee - Folge 1 - Der Einzug',
19 u'description': u'Folge 1 - Der Einzug',
20 },
21 u'params': {
22 u'skip_download': True,
23 },
24 u'skip': u'Only works from Germany',
25 },
26 {
27 u'url': u'http://rtl2now.rtl2.de/aerger-im-revier/episode-15-teil-1.php?film_id=69756&player=1&season=2&index=5',
28 u'file': u'69756.flv',
29 u'info_dict': {
30 u'upload_date': u'20120519',
31 u'title': u'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit...',
32 u'description': u'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit u.a.',
33 u'thumbnail': u'http://autoimg.static-fra.de/rtl2now/219850/1500x1500/image2.jpg',
34 },
35 u'params': {
36 u'skip_download': True,
37 },
38 u'skip': u'Only works from Germany',
39 },
40 {
41 u'url': u'www.voxnow.de/voxtours/suedafrika-reporter-ii.php?film_id=13883&player=1&season=17',
42 u'file': u'13883.flv',
43 u'info_dict': {
44 u'upload_date': u'20090627',
45 u'title': u'Voxtours - Südafrika-Reporter II',
46 u'description': u'Südafrika-Reporter II',
47 },
48 u'params': {
49 u'skip_download': True,
50 },
51 },
52 {
53 u'url': u'http://superrtlnow.de/medicopter-117/angst.php?film_id=99205&player=1',
54 u'file': u'99205.flv',
55 u'info_dict': {
56 u'upload_date': u'20080928',
57 u'title': u'Medicopter 117 - Angst!',
58 u'description': u'Angst!',
59 u'thumbnail': u'http://autoimg.static-fra.de/superrtlnow/287529/1500x1500/image2.jpg'
60 },
61 u'params': {
62 u'skip_download': True,
63 },
64 },
65 {
66 u'url': u'http://www.rtlnitronow.de/recht-ordnung/stadtpolizei-frankfurt-gerichtsvollzieher-leipzig.php?film_id=129679&player=1&season=1',
67 u'file': u'129679.flv',
68 u'info_dict': {
69 u'upload_date': u'20131016',
70 u'title': u'Recht & Ordnung - Stadtpolizei Frankfurt/ Gerichtsvollzieher...',
71 u'description': u'Stadtpolizei Frankfurt/ Gerichtsvollzieher Leipzig',
72 },
73 u'params': {
74 u'skip_download': True,
75 },
76 },
77 {
78 u'url': u'http://www.n-tvnow.de/top-gear/episode-1-2013-01-01-00-00-00.php?film_id=124903&player=1&season=10',
79 u'file': u'124903.flv',
80 u'info_dict': {
81 u'upload_date': u'20130101',
82 u'title': u'Top Gear vom 01.01.2013',
83 u'description': u'Episode 1',
84 },
85 u'params': {
86 u'skip_download': True,
87 },
88 u'skip': u'Only works from Germany',
89 }]
90
91
92 def _real_extract(self,url):
93 mobj = re.match(self._VALID_URL, url)
94
95 webpage_url = u'http://' + mobj.group('url')
96 video_page_url = u'http://' + mobj.group('base_url')
97 video_id = mobj.group(u'video_id')
98
99 webpage = self._download_webpage(webpage_url, video_id)
100
101 note_m = re.search(r'''(?sx)
102 <div[ ]style="margin-left:[ ]20px;[ ]font-size:[ ]13px;">(.*?)
103 <div[ ]id="playerteaser">''', webpage)
104 if note_m:
105 msg = clean_html(note_m.group(1))
106 raise ExtractorError(msg)
107
108 video_title = self._html_search_regex(r'<title>(?P<title>[^<]+?)( \| [^<]*)?</title>',
109 webpage, u'title')
110 playerdata_url = self._html_search_regex(r'\'playerdata\': \'(?P<playerdata_url>[^\']+)\'',
111 webpage, u'playerdata_url')
112
113 playerdata = self._download_webpage(playerdata_url, video_id)
114 mobj = re.search(r'<title><!\[CDATA\[(?P<description>.+?)(?:\s+- (?:Sendung )?vom (?P<upload_date_d>[0-9]{2})\.(?P<upload_date_m>[0-9]{2})\.(?:(?P<upload_date_Y>[0-9]{4})|(?P<upload_date_y>[0-9]{2})) [0-9]{2}:[0-9]{2} Uhr)?\]\]></title>', playerdata)
115 if mobj:
116 video_description = mobj.group(u'description')
117 if mobj.group('upload_date_Y'):
118 video_upload_date = mobj.group('upload_date_Y')
119 elif mobj.group('upload_date_y'):
120 video_upload_date = u'20' + mobj.group('upload_date_y')
121 else:
122 video_upload_date = None
123 if video_upload_date:
124 video_upload_date += mobj.group('upload_date_m')+mobj.group('upload_date_d')
125 else:
126 video_description = None
127 video_upload_date = None
128 self._downloader.report_warning(u'Unable to extract description and upload date')
129
130 # Thumbnail: not every video has an thumbnail
131 mobj = re.search(r'<meta property="og:image" content="(?P<thumbnail>[^"]+)">', webpage)
132 if mobj:
133 video_thumbnail = mobj.group(u'thumbnail')
134 else:
135 video_thumbnail = None
136
137 mobj = re.search(r'<filename [^>]+><!\[CDATA\[(?P<url>rtmpe://(?:[^/]+/){2})(?P<play_path>[^\]]+)\]\]></filename>', playerdata)
138 if mobj is None:
139 raise ExtractorError(u'Unable to extract media URL')
140 video_url = mobj.group(u'url')
141 video_play_path = u'mp4:' + mobj.group(u'play_path')
142 video_player_url = video_page_url + u'includes/vodplayer.swf'
143
144 return [{
145 'id': video_id,
146 'url': video_url,
147 'play_path': video_play_path,
148 'page_url': video_page_url,
149 'player_url': video_player_url,
150 'ext': 'flv',
151 'title': video_title,
152 'description': video_description,
153 'upload_date': video_upload_date,
154 'thumbnail': video_thumbnail,
155 }]