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