1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-11-27 20:53:22 +08:00
youtube-dl/youtube_dl/extractor/nowtv.py

194 lines
6.9 KiB
Python
Raw Normal View History

2015-05-28 01:20:32 +08:00
# coding: utf-8
2015-05-26 02:12:18 +08:00
from __future__ import unicode_literals
from .common import InfoExtractor
2015-05-28 01:20:32 +08:00
from ..compat import compat_str
2015-05-26 02:12:18 +08:00
from ..utils import (
ExtractorError,
2015-08-02 06:21:16 +08:00
determine_ext,
2015-05-26 02:12:18 +08:00
int_or_none,
2015-05-28 01:20:32 +08:00
parse_iso8601,
parse_duration,
remove_start,
2015-05-26 02:12:18 +08:00
)
2015-05-28 01:20:32 +08:00
class NowTVIE(InfoExtractor):
2015-08-07 21:50:54 +08:00
_VALID_URL = r'https?://(?:www\.)?nowtv\.(?:de|at|ch)/(?:rtl|rtl2|rtlnitro|superrtl|ntv|vox)/(?P<id>.+?)/(?:player|preview)'
2015-05-28 01:20:32 +08:00
_TESTS = [{
# rtl
'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/player',
'info_dict': {
'id': '203519',
'display_id': 'bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit',
2015-08-02 06:21:16 +08:00
'ext': 'flv',
2015-05-28 01:20:32 +08:00
'title': 'Die neuen Bauern und eine Hochzeit',
'description': 'md5:e234e1ed6d63cf06be5c070442612e7e',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432580700,
'upload_date': '20150525',
'duration': 2786,
},
'params': {
2015-08-02 06:21:16 +08:00
# rtmp download
2015-05-28 01:20:32 +08:00
'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',
2015-08-02 06:21:16 +08:00
'ext': 'flv',
2015-05-28 01:20:32 +08:00
'title': 'Berlin - Tag & Nacht (Folge 934)',
'description': 'md5:c85e88c2e36c552dfe63433bc9506dd0',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432666800,
'upload_date': '20150526',
'duration': 2641,
},
'params': {
2015-08-02 06:21:16 +08:00
# rtmp download
2015-05-28 01:20:32 +08:00
'skip_download': True,
},
2015-05-28 03:26:14 +08:00
}, {
# rtlnitro
'url': 'http://www.nowtv.de/rtlnitro/alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00/player',
'info_dict': {
'id': '165780',
'display_id': 'alarm-fuer-cobra-11-die-autobahnpolizei/hals-und-beinbruch-2014-08-23-21-10-00',
2015-08-02 06:21:16 +08:00
'ext': 'flv',
2015-05-28 03:26:14 +08:00
'title': 'Hals- und Beinbruch',
'description': 'md5:b50d248efffe244e6f56737f0911ca57',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432415400,
'upload_date': '20150523',
'duration': 2742,
},
'params': {
2015-08-02 06:21:16 +08:00
# rtmp download
2015-05-28 03:26:14 +08:00
'skip_download': True,
},
2015-05-28 01:20:32 +08:00
}, {
# superrtl
'url': 'http://www.nowtv.de/superrtl/medicopter-117/angst/player',
'info_dict': {
'id': '99205',
'display_id': 'medicopter-117/angst',
2015-08-02 06:21:16 +08:00
'ext': 'flv',
2015-05-28 01:20:32 +08:00
'title': 'Angst!',
'description': 'md5:30cbc4c0b73ec98bcd73c9f2a8c17c4e',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1222632900,
'upload_date': '20080928',
'duration': 3025,
},
'params': {
2015-08-02 06:21:16 +08:00
# rtmp download
2015-05-28 01:20:32 +08:00
'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',
2015-08-02 06:21:16 +08:00
'ext': 'flv',
2015-05-28 01:20:32 +08:00
'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': {
2015-08-02 06:21:16 +08:00
# rtmp download
2015-05-28 01:20:32 +08:00
'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',
2015-08-02 06:21:16 +08:00
'ext': 'flv',
2015-05-28 01:20:32 +08:00
'title': "Büro-Fall / Chihuahua 'Joel'",
'description': 'md5:e62cb6bf7c3cc669179d4f1eb279ad8d',
'thumbnail': 're:^https?://.*\.jpg$',
'timestamp': 1432408200,
'upload_date': '20150523',
'duration': 3092,
2015-05-26 02:12:18 +08:00
},
2015-05-28 01:20:32 +08:00
'params': {
2015-08-02 06:21:16 +08:00
# rtmp download
2015-05-28 01:20:32 +08:00
'skip_download': True,
},
2015-08-02 06:26:59 +08:00
}, {
'url': 'http://www.nowtv.de/rtl/bauer-sucht-frau/die-neuen-bauern-und-eine-hochzeit/preview',
'only_matching': True,
2015-08-07 21:51:09 +08:00
}, {
'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',
'only_matching': True,
2015-08-30 00:41:49 +08:00
}, {
'url': 'http://www.nowtv.de/rtl2/echtzeit/list/aktuell/schnelles-geld-am-ende-der-welt/player',
'only_matching': True,
2015-05-28 01:20:32 +08:00
}]
2015-05-26 02:12:18 +08:00
def _real_extract(self, url):
2015-08-02 06:21:16 +08:00
display_id = self._match_id(url)
2015-08-30 00:41:49 +08:00
display_id_split = display_id.split('/')
if len(display_id) > 2:
display_id = '/'.join((display_id_split[0], display_id_split[-1]))
2015-05-26 02:12:18 +08:00
2015-05-28 01:20:32 +08:00
info = self._download_json(
2015-07-14 00:11:05 +08:00
'https://api.nowtv.de/v3/movies/%s?fields=id,title,free,geoblocked,articleLong,articleShort,broadcastStartDate,seoUrl,duration,format,files' % display_id,
2015-05-28 01:20:32 +08:00
display_id)
video_id = compat_str(info['id'])
2015-05-26 02:12:18 +08:00
2015-05-28 01:41:43 +08:00
files = info['files']
if not files:
if info.get('geoblocked', False):
raise ExtractorError(
'Video %s is not available from your location due to geo restriction' % video_id,
expected=True)
if not info.get('free', True):
raise ExtractorError(
'Video %s is not available for free' % video_id, expected=True)
2015-05-28 01:20:32 +08:00
2015-05-26 02:12:18 +08:00
formats = []
2015-05-28 01:41:43 +08:00
for item in files['items']:
2015-08-02 06:21:16 +08:00
if determine_ext(item['path']) != 'f4v':
continue
app, play_path = remove_start(item['path'], '/').split('/', 1)
2015-05-28 01:20:32 +08:00
formats.append({
2015-08-02 06:21:16 +08:00
'url': 'rtmpe://fms.rtl.de',
'app': app,
'play_path': 'mp4:%s' % play_path,
'ext': 'flv',
'page_url': 'http://rtlnow.rtl.de',
'player_url': 'http://cdn.static-fra.de/now/vodplayer.swf',
2015-08-02 06:21:16 +08:00
'tbr': int_or_none(item.get('bitrate')),
2015-05-28 01:20:32 +08:00
})
2015-05-26 02:12:18 +08:00
self._sort_formats(formats)
2015-05-28 01:20:32 +08:00
title = info['title']
description = info.get('articleLong') or info.get('articleShort')
timestamp = parse_iso8601(info.get('broadcastStartDate'), ' ')
duration = parse_duration(info.get('duration'))
2015-08-02 06:21:16 +08:00
f = info.get('format', {})
2015-05-28 01:20:32 +08:00
thumbnail = f.get('defaultImage169Format') or f.get('defaultImage169Logo')
2015-05-26 02:12:18 +08:00
return {
'id': video_id,
2015-05-28 01:20:32 +08:00
'display_id': display_id,
2015-05-26 02:12:18 +08:00
'title': title,
'description': description,
'thumbnail': thumbnail,
2015-05-28 01:20:32 +08:00
'timestamp': timestamp,
2015-05-26 02:12:18 +08:00
'duration': duration,
'formats': formats,
}