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