]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/nowtv.py
[daum] fix IE_NAME
[youtube-dl.git] / youtube_dl / extractor / nowtv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9     ExtractorError,
10     determine_ext,
11     int_or_none,
12     parse_iso8601,
13     parse_duration,
14     remove_start,
15 )
16
17
18 class NowTVBaseIE(InfoExtractor):
19     _VIDEO_FIELDS = (
20         'id', 'title', 'free', 'geoblocked', 'articleLong', 'articleShort',
21         'broadcastStartDate', 'seoUrl', 'duration', 'files',
22         'format.defaultImage169Format', 'format.defaultImage169Logo')
23
24     def _extract_video(self, info, display_id=None):
25         video_id = compat_str(info['id'])
26
27         files = info['files']
28         if not files:
29             if info.get('geoblocked', False):
30                 raise ExtractorError(
31                     'Video %s is not available from your location due to geo restriction' % video_id,
32                     expected=True)
33             if not info.get('free', True):
34                 raise ExtractorError(
35                     'Video %s is not available for free' % video_id, expected=True)
36
37         formats = []
38         for item in files['items']:
39             if determine_ext(item['path']) != 'f4v':
40                 continue
41             app, play_path = remove_start(item['path'], '/').split('/', 1)
42             formats.append({
43                 'url': 'rtmpe://fms.rtl.de',
44                 'app': app,
45                 'play_path': 'mp4:%s' % play_path,
46                 'ext': 'flv',
47                 'page_url': 'http://rtlnow.rtl.de',
48                 'player_url': 'http://cdn.static-fra.de/now/vodplayer.swf',
49                 'tbr': int_or_none(item.get('bitrate')),
50             })
51         self._sort_formats(formats)
52
53         title = info['title']
54         description = info.get('articleLong') or info.get('articleShort')
55         timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
56         duration = parse_duration(info.get('duration'))
57
58         f = info.get('format', {})
59         thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
60
61         return {
62             'id': video_id,
63             'display_id': display_id or info.get('seoUrl'),
64             'title': title,
65             'description': description,
66             'thumbnail': thumbnail,
67             'timestamp': timestamp,
68             'duration': duration,
69             'formats': formats,
70         }
71
72
73 class NowTVIE(NowTVBaseIE):
74     _VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<show_id>[^/]+)/(?:(?:list/[^/]+|jahr/\d{4}/\d{1,2})/)?(?P<id>[^/]+)/(?:player|preview)'
75
76     _TESTS = [{
77         # rtl
78         'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player',
79         'info_dict': {
80             'id': '203519',
81             'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
82             'ext': 'flv',
83             'title': 'Inka Bause stellt die neuen Bauern vor',
84             'description': 'md5:e234e1ed6d63cf06be5c070442612e7e',
85             'thumbnail': 're:^https?://.*\.jpg$',
86             'timestamp': 1432580700,
87             'upload_date': '20150525',
88             'duration': 2786,
89         },
90         'params': {
91             # rtmp download
92             'skip_download': True,
93         },
94     }, {
95         # rtl2
96         'url': 'http://www.nowtv.de/rtl2/berlin-tag-nacht/berlin-tag-nacht-folge-934/player',
97         'info_dict': {
98             'id': '203481',
99             'display_id': 'berlin-tag-nacht/berlin-tag-nacht-folge-934',
100             'ext': 'flv',
101             'title': 'Berlin - Tag & Nacht (Folge 934)',
102             'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0',
103             'thumbnail': 're:^https?://.*\.jpg$',
104             'timestamp': 1432666800,
105             'upload_date': '20150526',
106             'duration': 2641,
107         },
108         'params': {
109             # rtmp download
110             'skip_download': True,
111         },
112     }, {
113         # rtlnitro
114         'url': 'http://www.nowtv.de/rtlnitro/alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00/player',
115         'info_dict': {
116             'id': '165780',
117             'display_id': 'alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00',
118             'ext': 'flv',
119             'title': 'Hals- und Beinbruch',
120             'description': 'md5:b50d248efffe244e6f56737f0911ca57',
121             'thumbnail': 're:^https?://.*\.jpg$',
122             'timestamp': 1432415400,
123             'upload_date': '20150523',
124             'duration': 2742,
125         },
126         'params': {
127             # rtmp download
128             'skip_download': True,
129         },
130     }, {
131         # superrtl
132         'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
133         'info_dict': {
134             'id': '99205',
135             'display_id': 'medicopter-117/angst',
136             'ext': 'flv',
137             'title': 'Angst!',
138             'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
139             'thumbnail': 're:^https?://.*\.jpg$',
140             'timestamp': 1222632900,
141             'upload_date': '20080928',
142             'duration': 3025,
143         },
144         'params': {
145             # rtmp download
146             'skip_download': True,
147         },
148     }, {
149         # ntv
150         'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player',
151         'info_dict': {
152             'id': '203521',
153             'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch',
154             'ext': 'flv',
155             'title': 'Thema u.a.: Der erste Blick: Die Apple Watch',
156             'description': 'md5:4312b6c9d839ffe7d8caf03865a531af',
157             'thumbnail': 're:^https?://.*\.jpg$',
158             'timestamp': 1432751700,
159             'upload_date': '20150527',
160             'duration': 1083,
161         },
162         'params': {
163             # rtmp download
164             'skip_download': True,
165         },
166     }, {
167         # vox
168         'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
169         'info_dict': {
170             'id': '128953',
171             'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel',
172             'ext': 'flv',
173             'title': "Büro-Fall / Chihuahua 'Joel'",
174             'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
175             'thumbnail': 're:^https?://.*\.jpg$',
176             'timestamp': 1432408200,
177             'upload_date': '20150523',
178             'duration': 3092,
179         },
180         'params': {
181             # rtmp download
182             'skip_download': True,
183         },
184     }, {
185         'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview',
186         'only_matching': True,
187     }, {
188         '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',
189         'only_matching': True,
190     }, {
191         'url': 'http://www.nowtv.de/rtl2/echtzeit/list/aktuell/schnelles-geld-am-ende-der-welt/player',
192         'only_matching': True,
193     }, {
194         'url': 'http://www.nowtv.de/rtl2/zuhause-im-glueck/jahr/2015/11/eine-erschuetternde-diagnose/player',
195         'only_matching': True,
196     }]
197
198     def _real_extract(self, url):
199         mobj = re.match(self._VALID_URL, url)
200         display_id = '%s/%s' % (mobj.group('show_id'), mobj.group('id'))
201
202         info = self._download_json(
203             'https://api.nowtv.de/v3/movies/%s?fields=%s'
204             % (display_id, ','.join(self._VIDEO_FIELDS)), display_id)
205
206         return self._extract_video(info, display_id)
207
208
209 class NowTVListIE(NowTVBaseIE):
210     _VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<show_id>[^/]+)/list/(?P<id>[^?/#&]+)$'
211
212     _SHOW_FIELDS = ('title', )
213     _SEASON_FIELDS = ('id', 'headline', 'seoheadline', )
214
215     _TESTS = [{
216         'url': 'http://www.nowtv.at/rtl/stern-tv/list/aktuell',
217         'info_dict': {
218             'id': '17006',
219             'title': 'stern TV - Aktuell',
220         },
221         'playlist_count': 1,
222     }, {
223         'url': 'http://www.nowtv.at/rtl/das-supertalent/list/free-staffel-8',
224         'info_dict': {
225             'id': '20716',
226             'title': 'Das Supertalent - FREE Staffel 8',
227         },
228         'playlist_count': 14,
229     }]
230
231     def _real_extract(self, url):
232         mobj = re.match(self._VALID_URL, url)
233         show_id = mobj.group('show_id')
234         season_id = mobj.group('id')
235
236         fields = []
237         fields.extend(self._SHOW_FIELDS)
238         fields.extend('formatTabs.%s' % field for field in self._SEASON_FIELDS)
239         fields.extend(
240             'formatTabs.formatTabPages.container.movies.%s' % field
241             for field in self._VIDEO_FIELDS)
242
243         list_info = self._download_json(
244             'https://api.nowtv.de/v3/formats/seo?fields=%s&name=%s.php'
245             % (','.join(fields), show_id),
246             season_id)
247
248         season = next(
249             season for season in list_info['formatTabs']['items']
250             if season.get('seoheadline') == season_id)
251
252         title = '%s - %s' % (list_info['title'], season['headline'])
253
254         entries = []
255         for container in season['formatTabPages']['items']:
256             for info in ((container.get('container') or {}).get('movies') or {}).get('items') or []:
257                 entries.append(self._extract_video(info))
258
259         return self.playlist_result(
260             entries, compat_str(season.get('id') or season_id), title)