]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/nowtv.py
[pbs] Allow empty attribute in player regex
[yt-dlp.git] / youtube_dl / extractor / nowtv.py
CommitLineData
b25b645d 1# coding: utf-8
5d0a33ee
AK
2from __future__ import unicode_literals
3
5d0a33ee 4from .common import InfoExtractor
b25b645d 5from ..compat import compat_str
5d0a33ee
AK
6from ..utils import (
7 ExtractorError,
cdc682d5 8 determine_ext,
5d0a33ee 9 int_or_none,
b25b645d
S
10 parse_iso8601,
11 parse_duration,
12 remove_start,
5d0a33ee
AK
13)
14
5d0a33ee 15
b25b645d 16class NowTVIE(InfoExtractor):
acc1adbe 17 _VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<id>.+?)/(?:player|preview)'
b25b645d
S
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',
cdc682d5 25 'ext': 'flv',
b25b645d
S
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': {
cdc682d5 34 # rtmp download
b25b645d
S
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',
cdc682d5 43 'ext': 'flv',
b25b645d
S
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': {
cdc682d5 52 # rtmp download
b25b645d
S
53 'skip_download': True,
54 },
9e0b5791
S
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',
cdc682d5 61 'ext': 'flv',
9e0b5791
S
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': {
cdc682d5 70 # rtmp download
9e0b5791
S
71 'skip_download': True,
72 },
b25b645d
S
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',
cdc682d5 79 'ext': 'flv',
b25b645d
S
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': {
cdc682d5 88 # rtmp download
b25b645d
S
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',
cdc682d5 97 'ext': 'flv',
b25b645d
S
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': {
cdc682d5 106 # rtmp download
b25b645d
S
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',
cdc682d5 115 'ext': 'flv',
b25b645d
S
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,
5d0a33ee 122 },
b25b645d 123 'params': {
cdc682d5 124 # rtmp download
b25b645d
S
125 'skip_download': True,
126 },
e422d7f4
S
127 }, {
128 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview',
129 'only_matching': True,
0f422256
S
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,
c88e118b
S
133 }, {
134 'url': 'http://www.nowtv.de/rtl2/echtzeit/list/aktuell/schnelles-geld-am-ende-der-welt/player',
135 'only_matching': True,
b25b645d 136 }]
5d0a33ee
AK
137
138 def _real_extract(self, url):
cdc682d5 139 display_id = self._match_id(url)
c88e118b
S
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]))
5d0a33ee 143
b25b645d 144 info = self._download_json(
6dfa0602 145 'https://api.nowtv.de/v3/movies/%s?fields=id,title,free,geoblocked,articleLong,articleShort,broadcastStartDate,seoUrl,duration,format,files' % display_id,
b25b645d
S
146 display_id)
147
148 video_id = compat_str(info['id'])
5d0a33ee 149
9b254aa1
S
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)
b25b645d 159
5d0a33ee 160 formats = []
9b254aa1 161 for item in files['items']:
cdc682d5
S
162 if determine_ext(item['path']) != 'f4v':
163 continue
164 app, play_path = remove_start(item['path'], '/').split('/', 1)
b25b645d 165 formats.append({
cdc682d5
S
166 'url': 'rtmpe://fms.rtl.de',
167 'app': app,
168 'play_path': 'mp4:%s' % play_path,
169 'ext': 'flv',
170 'page_url': url,
171 'player_url': 'http://rtl-now.rtl.de/includes/nc_player.swf',
172 'tbr': int_or_none(item.get('bitrate')),
b25b645d 173 })
5d0a33ee
AK
174 self._sort_formats(formats)
175
b25b645d
S
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'))
cdc682d5
S
180
181 f = info.get('format', {})
b25b645d
S
182 thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
183
5d0a33ee
AK
184 return {
185 'id': video_id,
b25b645d 186 'display_id': display_id,
5d0a33ee
AK
187 'title': title,
188 'description': description,
189 'thumbnail': thumbnail,
b25b645d 190 'timestamp': timestamp,
5d0a33ee
AK
191 'duration': duration,
192 'formats': formats,
193 }