]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/nowtv.py
Update version in the changelog.
[youtubedl] / youtube_dl / extractor / nowtv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_str
6 from ..utils import (
7 ExtractorError,
8 determine_ext,
9 int_or_none,
10 parse_iso8601,
11 parse_duration,
12 remove_start,
13 )
14
15
16 class NowTVIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<id>.+?)/(?:player|preview)'
18
19 _TESTS = [{
20 # rtl
21 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player',
22 'info_dict': {
23 'id': '203519',
24 'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
25 'ext': 'flv',
26 'title': 'Die neuen Bauern und eine Hochzeit',
27 'description': 'md5:e234e1ed6d63cf06be5c070442612e7e',
28 'thumbnail': 're:^https?://.*\.jpg$',
29 'timestamp': 1432580700,
30 'upload_date': '20150525',
31 'duration': 2786,
32 },
33 'params': {
34 # rtmp download
35 'skip_download': True,
36 },
37 }, {
38 # rtl2
39 'url': 'http://www.nowtv.de/rtl2/berlin-tag-nacht/berlin-tag-nacht-folge-934/player',
40 'info_dict': {
41 'id': '203481',
42 'display_id': 'berlin-tag-nacht/berlin-tag-nacht-folge-934',
43 'ext': 'flv',
44 'title': 'Berlin - Tag & Nacht (Folge 934)',
45 'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0',
46 'thumbnail': 're:^https?://.*\.jpg$',
47 'timestamp': 1432666800,
48 'upload_date': '20150526',
49 'duration': 2641,
50 },
51 'params': {
52 # rtmp download
53 'skip_download': True,
54 },
55 }, {
56 # rtlnitro
57 'url': 'http://www.nowtv.de/rtlnitro/alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00/player',
58 'info_dict': {
59 'id': '165780',
60 'display_id': 'alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00',
61 'ext': 'flv',
62 'title': 'Hals- und Beinbruch',
63 'description': 'md5:b50d248efffe244e6f56737f0911ca57',
64 'thumbnail': 're:^https?://.*\.jpg$',
65 'timestamp': 1432415400,
66 'upload_date': '20150523',
67 'duration': 2742,
68 },
69 'params': {
70 # rtmp download
71 'skip_download': True,
72 },
73 }, {
74 # superrtl
75 'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
76 'info_dict': {
77 'id': '99205',
78 'display_id': 'medicopter-117/angst',
79 'ext': 'flv',
80 'title': 'Angst!',
81 'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
82 'thumbnail': 're:^https?://.*\.jpg$',
83 'timestamp': 1222632900,
84 'upload_date': '20080928',
85 'duration': 3025,
86 },
87 'params': {
88 # rtmp download
89 'skip_download': True,
90 },
91 }, {
92 # ntv
93 'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player',
94 'info_dict': {
95 'id': '203521',
96 'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch',
97 'ext': 'flv',
98 'title': 'Thema u.a.: Der erste Blick: Die Apple Watch',
99 'description': 'md5:4312b6c9d839ffe7d8caf03865a531af',
100 'thumbnail': 're:^https?://.*\.jpg$',
101 'timestamp': 1432751700,
102 'upload_date': '20150527',
103 'duration': 1083,
104 },
105 'params': {
106 # rtmp download
107 'skip_download': True,
108 },
109 }, {
110 # vox
111 'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
112 'info_dict': {
113 'id': '128953',
114 'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel',
115 'ext': 'flv',
116 'title': "Büro-Fall / Chihuahua 'Joel'",
117 'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
118 'thumbnail': 're:^https?://.*\.jpg$',
119 'timestamp': 1432408200,
120 'upload_date': '20150523',
121 'duration': 3092,
122 },
123 'params': {
124 # rtmp download
125 'skip_download': True,
126 },
127 }, {
128 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview',
129 'only_matching': True,
130 }, {
131 'url': 'http://www.nowtv.at/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview?return=/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
132 'only_matching': True,
133 }, {
134 'url': 'http://www.nowtv.de/rtl2/echtzeit/list/aktuell/schnelles-geld-am-ende-der-welt/player',
135 'only_matching': True,
136 }]
137
138 def _real_extract(self, url):
139 display_id = self._match_id(url)
140 display_id_split = display_id.split('/')
141 if len(display_id) > 2:
142 display_id = '/'.join((display_id_split[0], display_id_split[-1]))
143
144 info = self._download_json(
145 'https://api.nowtv.de/v3/movies/%s?fields=id,title,free,geoblocked,articleLong,articleShort,broadcastStartDate,seoUrl,duration,format,files' % display_id,
146 display_id)
147
148 video_id = compat_str(info['id'])
149
150 files = info['files']
151 if not files:
152 if info.get('geoblocked', False):
153 raise ExtractorError(
154 'Video %s is not available from your location due to geo restriction' % video_id,
155 expected=True)
156 if not info.get('free', True):
157 raise ExtractorError(
158 'Video %s is not available for free' % video_id, expected=True)
159
160 formats = []
161 for item in files['items']:
162 if determine_ext(item['path']) != 'f4v':
163 continue
164 app, play_path = remove_start(item['path'], '/').split('/', 1)
165 formats.append({
166 'url': 'rtmpe://fms.rtl.de',
167 'app': app,
168 'play_path': 'mp4:%s' % play_path,
169 'ext': 'flv',
170 'page_url': 'http://rtlnow.rtl.de',
171 'player_url': 'http://cdn.static-fra.de/now/vodplayer.swf',
172 'tbr': int_or_none(item.get('bitrate')),
173 })
174 self._sort_formats(formats)
175
176 title = info['title']
177 description = info.get('articleLong') or info.get('articleShort')
178 timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
179 duration = parse_duration(info.get('duration'))
180
181 f = info.get('format', {})
182 thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
183
184 return {
185 'id': video_id,
186 'display_id': display_id,
187 'title': title,
188 'description': description,
189 'thumbnail': thumbnail,
190 'timestamp': timestamp,
191 'duration': duration,
192 'formats': formats,
193 }