]>
Commit | Line | Data |
---|---|---|
b25b645d | 1 | # coding: utf-8 |
5d0a33ee AK |
2 | from __future__ import unicode_literals |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
b25b645d | 7 | from ..compat import compat_str |
5d0a33ee AK |
8 | from ..utils import ( |
9 | ExtractorError, | |
5d0a33ee | 10 | int_or_none, |
b25b645d S |
11 | parse_iso8601, |
12 | parse_duration, | |
13 | remove_start, | |
5d0a33ee AK |
14 | ) |
15 | ||
5d0a33ee | 16 | |
b25b645d S |
17 | class NowTVIE(InfoExtractor): |
18 | _VALID_URL = r'https?://(?:www\.)?nowtv\.de/(?P<station>rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<id>.+?)/player' | |
19 | ||
20 | _TESTS = [{ | |
21 | # rtl | |
22 | 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player', | |
23 | 'info_dict': { | |
24 | 'id': '203519', | |
25 | 'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit', | |
26 | 'ext': 'mp4', | |
27 | 'title': 'Die neuen Bauern und eine Hochzeit', | |
28 | 'description': 'md5:e234e1ed6d63cf06be5c070442612e7e', | |
29 | 'thumbnail': 're:^https?://.*\.jpg$', | |
30 | 'timestamp': 1432580700, | |
31 | 'upload_date': '20150525', | |
32 | 'duration': 2786, | |
33 | }, | |
34 | 'params': { | |
35 | # m3u8 download | |
36 | 'skip_download': True, | |
37 | }, | |
38 | }, { | |
39 | # rtl2 | |
40 | 'url': 'http://www.nowtv.de/rtl2/berlin-tag-nacht/berlin-tag-nacht-folge-934/player', | |
41 | 'info_dict': { | |
42 | 'id': '203481', | |
43 | 'display_id': 'berlin-tag-nacht/berlin-tag-nacht-folge-934', | |
44 | 'ext': 'mp4', | |
45 | 'title': 'Berlin - Tag & Nacht (Folge 934)', | |
46 | 'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0', | |
47 | 'thumbnail': 're:^https?://.*\.jpg$', | |
48 | 'timestamp': 1432666800, | |
49 | 'upload_date': '20150526', | |
50 | 'duration': 2641, | |
51 | }, | |
52 | 'params': { | |
53 | # m3u8 download | |
54 | 'skip_download': True, | |
55 | }, | |
56 | }, { | |
57 | # superrtl | |
58 | 'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player', | |
59 | 'info_dict': { | |
60 | 'id': '99205', | |
61 | 'display_id': 'medicopter-117/angst', | |
62 | 'ext': 'mp4', | |
63 | 'title': 'Angst!', | |
64 | 'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e', | |
65 | 'thumbnail': 're:^https?://.*\.jpg$', | |
66 | 'timestamp': 1222632900, | |
67 | 'upload_date': '20080928', | |
68 | 'duration': 3025, | |
69 | }, | |
70 | 'params': { | |
71 | # m3u8 download | |
72 | 'skip_download': True, | |
73 | }, | |
74 | }, { | |
75 | # ntv | |
76 | 'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player', | |
77 | 'info_dict': { | |
78 | 'id': '203521', | |
79 | 'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch', | |
80 | 'ext': 'mp4', | |
81 | 'title': 'Thema u.a.: Der erste Blick: Die Apple Watch', | |
82 | 'description': 'md5:4312b6c9d839ffe7d8caf03865a531af', | |
83 | 'thumbnail': 're:^https?://.*\.jpg$', | |
84 | 'timestamp': 1432751700, | |
85 | 'upload_date': '20150527', | |
86 | 'duration': 1083, | |
87 | }, | |
88 | 'params': { | |
89 | # m3u8 download | |
90 | 'skip_download': True, | |
91 | }, | |
92 | }, { | |
93 | # vox | |
94 | 'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player', | |
95 | 'info_dict': { | |
96 | 'id': '128953', | |
97 | 'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel', | |
98 | 'ext': 'mp4', | |
99 | 'title': "Büro-Fall / Chihuahua 'Joel'", | |
100 | 'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d', | |
101 | 'thumbnail': 're:^https?://.*\.jpg$', | |
102 | 'timestamp': 1432408200, | |
103 | 'upload_date': '20150523', | |
104 | 'duration': 3092, | |
5d0a33ee | 105 | }, |
b25b645d S |
106 | 'params': { |
107 | # m3u8 download | |
108 | 'skip_download': True, | |
109 | }, | |
110 | }] | |
5d0a33ee AK |
111 | |
112 | def _real_extract(self, url): | |
113 | mobj = re.match(self._VALID_URL, url) | |
b25b645d S |
114 | display_id = mobj.group('id') |
115 | station = mobj.group('station') | |
5d0a33ee | 116 | |
b25b645d | 117 | info = self._download_json( |
ff4a1279 | 118 | 'https://api.nowtv.de/v3/movies/%s?fields=*,format,files' % display_id, |
b25b645d S |
119 | display_id) |
120 | ||
121 | video_id = compat_str(info['id']) | |
5d0a33ee | 122 | |
9b254aa1 S |
123 | files = info['files'] |
124 | if not files: | |
125 | if info.get('geoblocked', False): | |
126 | raise ExtractorError( | |
127 | 'Video %s is not available from your location due to geo restriction' % video_id, | |
128 | expected=True) | |
129 | if not info.get('free', True): | |
130 | raise ExtractorError( | |
131 | 'Video %s is not available for free' % video_id, expected=True) | |
b25b645d S |
132 | |
133 | f = info.get('format', {}) | |
134 | station = f.get('station') or station | |
135 | ||
136 | STATIONS = { | |
137 | 'rtl': 'rtlnow', | |
138 | 'rtl2': 'rtl2now', | |
139 | 'vox': 'voxnow', | |
140 | 'nitro': 'rtlnitronow', | |
141 | 'ntv': 'n-tvnow', | |
142 | 'superrtl': 'superrtlnow' | |
143 | } | |
5d0a33ee AK |
144 | |
145 | formats = [] | |
9b254aa1 | 146 | for item in files['items']: |
b25b645d S |
147 | item_path = remove_start(item['path'], '/') |
148 | tbr = int_or_none(item['bitrate']) | |
149 | m3u8_url = 'http://hls.fra.%s.de/hls-vod-enc/%s.m3u8' % (STATIONS[station], item_path) | |
150 | m3u8_url = m3u8_url.replace('now/', 'now/videos/') | |
151 | formats.append({ | |
152 | 'url': m3u8_url, | |
153 | 'format_id': '%s-%sk' % (item['id'], tbr), | |
5d0a33ee | 154 | 'ext': 'mp4', |
b25b645d S |
155 | 'tbr': tbr, |
156 | }) | |
5d0a33ee AK |
157 | self._sort_formats(formats) |
158 | ||
b25b645d S |
159 | title = info['title'] |
160 | description = info.get('articleLong') or info.get('articleShort') | |
161 | timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ') | |
162 | duration = parse_duration(info.get('duration')) | |
163 | thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo') | |
164 | ||
5d0a33ee AK |
165 | return { |
166 | 'id': video_id, | |
b25b645d | 167 | 'display_id': display_id, |
5d0a33ee AK |
168 | 'title': title, |
169 | 'description': description, | |
170 | 'thumbnail': thumbnail, | |
b25b645d | 171 | 'timestamp': timestamp, |
5d0a33ee AK |
172 | 'duration': duration, |
173 | 'formats': formats, | |
174 | } |