[nowtv] Improve and simplify

master
Sergey M․ 9 years ago
parent 5d0a33eebc
commit b25b645d51

@ -355,7 +355,7 @@ from .normalboots import NormalbootsIE
from .nosvideo import NosVideoIE from .nosvideo import NosVideoIE
from .novamov import NovaMovIE from .novamov import NovaMovIE
from .nowness import NownessIE from .nowness import NownessIE
from .nowtv import NowTvIE from .nowtv import NowTVIE
from .nowvideo import NowVideoIE from .nowvideo import NowVideoIE
from .npo import ( from .npo import (
NPOIE, NPOIE,

@ -1,90 +1,169 @@
# encoding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_str
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
qualities,
unified_strdate,
int_or_none, int_or_none,
parse_iso8601,
parse_duration,
remove_start,
) )
class NowTvIE(InfoExtractor):
"""Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW"""
_VALID_URL = r'''(?x)
(?:https?://)?
(
(?:www\.)?nowtv\.de
/(rtl|rtl2|rtlnitro||superrtl|ntv|vox)(?P<path>/.*?)/player
)'''
_TESTS = [ class NowTVIE(InfoExtractor):
{ _VALID_URL = r'https?://(?:www\.)?nowtv\.de/(?P<station>rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<id>.+?)/player'
'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
'info_dict': { _TESTS = [{
'id': '128953', # rtl
'ext': 'mp4', 'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player',
'title': 'B\u00fcro-Fall \/ Chihuahua \'Joel\'', 'info_dict': {
'description': 'md5:ce843b6b5901d9a7f7d04d1bbcdb12de', 'id': '203519',
'upload_date': '2015-05-23 19:10:00', 'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
'duration': '00:51:32', 'ext': 'mp4',
}, 'title': 'Die neuen Bauern und eine Hochzeit',
'params': { 'description': 'md5:e234e1ed6d63cf06be5c070442612e7e',
'skip_download': True, 'thumbnail': 're:^https?://.*\.jpg$',
}, 'timestamp': 1432580700,
'skip': 'Only works from Germany', 'upload_date': '20150525',
'duration': 2786,
},
'params': {
# m3u8 download
'skip_download': True,
},
}, {
# rtl2
'url': 'http://www.nowtv.de/rtl2/berlin-tag-nacht/berlin-tag-nacht-folge-934/player',
'info_dict': {
'id': '203481',
'display_id': 'berlin-tag-nacht/berlin-tag-nacht-folge-934',
'ext': 'mp4',
'title': 'Berlin - Tag & Nacht (Folge 934)',
'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432666800,
'upload_date': '20150526',
'duration': 2641,
},
'params': {
# m3u8 download
'skip_download': True,
},
}, {
# superrtl
'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
'info_dict': {
'id': '99205',
'display_id': 'medicopter-117/angst',
'ext': 'mp4',
'title': 'Angst!',
'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1222632900,
'upload_date': '20080928',
'duration': 3025,
},
'params': {
# m3u8 download
'skip_download': True,
},
}, {
# ntv
'url': 'http://www.nowtv.de/ntv/ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch/player',
'info_dict': {
'id': '203521',
'display_id': 'ratgeber-geld/thema-ua-der-erste-blick-die-apple-watch',
'ext': 'mp4',
'title': 'Thema u.a.: Der erste Blick: Die Apple Watch',
'description': 'md5:4312b6c9d839ffe7d8caf03865a531af',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432751700,
'upload_date': '20150527',
'duration': 1083,
},
'params': {
# m3u8 download
'skip_download': True,
},
}, {
# vox
'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
'info_dict': {
'id': '128953',
'display_id': 'der-hundeprofi/buero-fall-chihuahua-joel',
'ext': 'mp4',
'title': "Büro-Fall / Chihuahua 'Joel'",
'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432408200,
'upload_date': '20150523',
'duration': 3092,
}, },
] 'params': {
# m3u8 download
'skip_download': True,
},
}]
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
info_url = 'https://api.nowtv.de/v3/movies' + mobj.group('path') + '?fields=*,format,files,breakpoints,paymentPaytypes,trailers' display_id = mobj.group('id')
info = self._download_json(info_url, None) station = mobj.group('station')
video_id = info['id'] info = self._download_json(
title = info['title'] 'https://api.nowtv.de/v3/movies/%s?fields=*,format,files,breakpoints,paymentPaytypes,trailers,pictures' % display_id,
description = info['articleShort'] display_id)
duration = info['duration']
upload_date = unified_strdate(info['broadcastStartDate']) video_id = compat_str(info['id'])
free = info['free']
station = info['format']['station']
thumbnail = info['format']['defaultImage169Logo']
if station == 'rtl': if info.get('geoblocked'):
base_url = 'http://hls.fra.rtlnow.de/hls-vod-enc/' raise ExtractorError(
elif station == 'rtl2': 'Video %s is not available from your location due to geo restriction' % video_id,
base_url = 'http://hls.fra.rtl2now.de/hls-vod-enc/' expected=True)
elif station == 'vox':
base_url = 'http://hls.fra.voxnow.de/hls-vod-enc/' f = info.get('format', {})
elif station == 'nitro': station = f.get('station') or station
base_url = 'http://hls.fra.rtlnitronow.de/hls-vod-enc/'
elif station == 'ntv': STATIONS = {
base_url = 'http://hls.fra.n-tvnow.de/hls-vod-enc/' 'rtl': 'rtlnow',
elif station == 'superrtl': 'rtl2': 'rtl2now',
base_url = 'http://hls.fra.superrtlnow.de/hls-vod-enc/' 'vox': 'voxnow',
'nitro': 'rtlnitronow',
'ntv': 'n-tvnow',
'superrtl': 'superrtlnow'
}
formats = [] formats = []
for item in info['files']['items']: for item in info['files']['items']:
if item['type'] != 'video/x-abr': item_path = remove_start(item['path'], '/')
continue tbr = int_or_none(item['bitrate'])
m3u8_url = 'http://hls.fra.%s.de/hls-vod-enc/%s.m3u8' % (STATIONS[station], item_path)
fmt = { m3u8_url = m3u8_url.replace('now/', 'now/videos/')
'url': base_url + item['path'] + '.m3u8', formats.append({
'tbr': int_or_none(item['bitrate']), 'url': m3u8_url,
'format_id': '%s-%sk' % (item['id'], tbr),
'ext': 'mp4', 'ext': 'mp4',
'format_id': int_or_none(item['id']), 'tbr': tbr,
} })
formats.append(fmt)
self._sort_formats(formats) self._sort_formats(formats)
title = info['title']
description = info.get('articleLong') or info.get('articleShort')
timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
duration = parse_duration(info.get('duration'))
thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
return { return {
'id': video_id, 'id': video_id,
'display_id': display_id,
'title': title, 'title': title,
'description': description, 'description': description,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'upload_date': upload_date, 'timestamp': timestamp,
'duration': duration, 'duration': duration,
'formats': formats, 'formats': formats,
} }

Loading…
Cancel
Save