1
0
mirror of https://github.com/l1ving/youtube-dl synced 2024-12-22 14:22:58 +08:00

[rtlnow] Simplify

This commit is contained in:
Philipp Hagemeister 2014-01-25 14:18:54 +01:00
parent 59188de113
commit f945612bd0

View File

@ -1,4 +1,7 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
@ -12,78 +15,77 @@ class RTLnowIE(InfoExtractor):
"""Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW""" """Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW"""
_VALID_URL = r'(?:http://)?(?P<url>(?P<domain>rtl-now\.rtl\.de|rtl2now\.rtl2\.de|(?:www\.)?voxnow\.de|(?:www\.)?rtlnitronow\.de|(?:www\.)?superrtlnow\.de|(?:www\.)?n-tvnow\.de)/+[a-zA-Z0-9-]+/[a-zA-Z0-9-]+\.php\?(?:container_id|film_id)=(?P<video_id>[0-9]+)&player=1(?:&season=[0-9]+)?(?:&.*)?)' _VALID_URL = r'(?:http://)?(?P<url>(?P<domain>rtl-now\.rtl\.de|rtl2now\.rtl2\.de|(?:www\.)?voxnow\.de|(?:www\.)?rtlnitronow\.de|(?:www\.)?superrtlnow\.de|(?:www\.)?n-tvnow\.de)/+[a-zA-Z0-9-]+/[a-zA-Z0-9-]+\.php\?(?:container_id|film_id)=(?P<video_id>[0-9]+)&player=1(?:&season=[0-9]+)?(?:&.*)?)'
_TESTS = [{ _TESTS = [{
u'url': u'http://rtl-now.rtl.de/ahornallee/folge-1.php?film_id=90419&player=1&season=1', 'url': 'http://rtl-now.rtl.de/ahornallee/folge-1.php?film_id=90419&player=1&season=1',
u'file': u'90419.flv', 'file': '90419.flv',
u'info_dict': { 'info_dict': {
u'upload_date': u'20070416', 'upload_date': '20070416',
u'title': u'Ahornallee - Folge 1 - Der Einzug', 'title': 'Ahornallee - Folge 1 - Der Einzug',
u'description': u'Folge 1 - Der Einzug', 'description': 'Folge 1 - Der Einzug',
}, },
u'params': { 'params': {
u'skip_download': True, 'skip_download': True,
}, },
u'skip': u'Only works from Germany', 'skip': 'Only works from Germany',
}, },
{ {
u'url': u'http://rtl2now.rtl2.de/aerger-im-revier/episode-15-teil-1.php?film_id=69756&player=1&season=2&index=5', 'url': 'http://rtl2now.rtl2.de/aerger-im-revier/episode-15-teil-1.php?film_id=69756&player=1&season=2&index=5',
u'file': u'69756.flv', 'file': '69756.flv',
u'info_dict': { 'info_dict': {
u'upload_date': u'20120519', 'upload_date': '20120519',
u'title': u'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit...', 'title': 'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit...',
u'description': u'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit u.a.', 'description': 'Ärger im Revier - Ein junger Ladendieb, ein handfester Streit u.a.',
u'thumbnail': u'http://autoimg.static-fra.de/rtl2now/219850/1500x1500/image2.jpg', 'thumbnail': 'http://autoimg.static-fra.de/rtl2now/219850/1500x1500/image2.jpg',
}, },
u'params': { 'params': {
u'skip_download': True, 'skip_download': True,
}, },
u'skip': u'Only works from Germany', 'skip': 'Only works from Germany',
}, },
{ {
u'url': u'http://www.voxnow.de/voxtours/suedafrika-reporter-ii.php?film_id=13883&player=1&season=17', 'url': 'http://www.voxnow.de/voxtours/suedafrika-reporter-ii.php?film_id=13883&player=1&season=17',
u'file': u'13883.flv', 'file': '13883.flv',
u'info_dict': { 'info_dict': {
u'upload_date': u'20090627', 'upload_date': '20090627',
u'title': u'Voxtours - Südafrika-Reporter II', 'title': 'Voxtours - Südafrika-Reporter II',
u'description': u'Südafrika-Reporter II', 'description': 'Südafrika-Reporter II',
}, },
u'params': { 'params': {
u'skip_download': True, 'skip_download': True,
}, },
}, },
{ {
u'url': u'http://superrtlnow.de/medicopter-117/angst.php?film_id=99205&player=1', 'url': 'http://superrtlnow.de/medicopter-117/angst.php?film_id=99205&player=1',
u'file': u'99205.flv', 'file': '99205.flv',
u'info_dict': { 'info_dict': {
u'upload_date': u'20080928', 'upload_date': '20080928',
u'title': u'Medicopter 117 - Angst!', 'title': 'Medicopter 117 - Angst!',
u'description': u'Angst!', 'description': 'Angst!',
u'thumbnail': u'http://autoimg.static-fra.de/superrtlnow/287529/1500x1500/image2.jpg' 'thumbnail': 'http://autoimg.static-fra.de/superrtlnow/287529/1500x1500/image2.jpg'
}, },
u'params': { 'params': {
u'skip_download': True, 'skip_download': True,
}, },
}, },
{ {
u'url': u'http://www.n-tvnow.de/top-gear/episode-1-2013-01-01-00-00-00.php?film_id=124903&player=1&season=10', 'url': 'http://www.n-tvnow.de/top-gear/episode-1-2013-01-01-00-00-00.php?film_id=124903&player=1&season=10',
u'file': u'124903.flv', 'file': '124903.flv',
u'info_dict': { 'info_dict': {
u'upload_date': u'20130101', 'upload_date': '20130101',
u'title': u'Top Gear vom 01.01.2013', 'title': 'Top Gear vom 01.01.2013',
u'description': u'Episode 1', 'description': 'Episode 1',
}, },
u'params': { 'params': {
u'skip_download': True, 'skip_download': True,
}, },
u'skip': u'Only works from Germany', 'skip': 'Only works from Germany',
}] }]
def _real_extract(self, url):
def _real_extract(self,url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
webpage_url = u'http://' + mobj.group('url') webpage_url = 'http://' + mobj.group('url')
video_page_url = u'http://' + mobj.group('domain') + u'/' video_page_url = 'http://' + mobj.group('domain') + '/'
video_id = mobj.group(u'video_id') video_id = mobj.group('video_id')
webpage = self._download_webpage(webpage_url, video_id) webpage = self._download_webpage(webpage_url, video_id)
@ -94,43 +96,45 @@ class RTLnowIE(InfoExtractor):
msg = clean_html(note_m.group(1)) msg = clean_html(note_m.group(1))
raise ExtractorError(msg) raise ExtractorError(msg)
video_title = self._html_search_regex(r'<title>(?P<title>[^<]+?)( \| [^<]*)?</title>', video_title = self._html_search_regex(
webpage, u'title') r'<title>(?P<title>[^<]+?)( \| [^<]*)?</title>',
playerdata_url = self._html_search_regex(r'\'playerdata\': \'(?P<playerdata_url>[^\']+)\'', webpage, 'title')
webpage, u'playerdata_url') playerdata_url = self._html_search_regex(
r'\'playerdata\': \'(?P<playerdata_url>[^\']+)\'',
webpage, 'playerdata_url')
playerdata = self._download_webpage(playerdata_url, video_id) playerdata = self._download_webpage(playerdata_url, video_id)
mobj = re.search(r'<title><!\[CDATA\[(?P<description>.+?)(?:\s+- (?:Sendung )?vom (?P<upload_date_d>[0-9]{2})\.(?P<upload_date_m>[0-9]{2})\.(?:(?P<upload_date_Y>[0-9]{4})|(?P<upload_date_y>[0-9]{2})) [0-9]{2}:[0-9]{2} Uhr)?\]\]></title>', playerdata) mobj = re.search(r'<title><!\[CDATA\[(?P<description>.+?)(?:\s+- (?:Sendung )?vom (?P<upload_date_d>[0-9]{2})\.(?P<upload_date_m>[0-9]{2})\.(?:(?P<upload_date_Y>[0-9]{4})|(?P<upload_date_y>[0-9]{2})) [0-9]{2}:[0-9]{2} Uhr)?\]\]></title>', playerdata)
if mobj: if mobj:
video_description = mobj.group(u'description') video_description = mobj.group('description')
if mobj.group('upload_date_Y'): if mobj.group('upload_date_Y'):
video_upload_date = mobj.group('upload_date_Y') video_upload_date = mobj.group('upload_date_Y')
elif mobj.group('upload_date_y'): elif mobj.group('upload_date_y'):
video_upload_date = u'20' + mobj.group('upload_date_y') video_upload_date = '20' + mobj.group('upload_date_y')
else: else:
video_upload_date = None video_upload_date = None
if video_upload_date: if video_upload_date:
video_upload_date += mobj.group('upload_date_m')+mobj.group('upload_date_d') video_upload_date += mobj.group('upload_date_m') + mobj.group('upload_date_d')
else: else:
video_description = None video_description = None
video_upload_date = None video_upload_date = None
self._downloader.report_warning(u'Unable to extract description and upload date') self._downloader.report_warning('Unable to extract description and upload date')
# Thumbnail: not every video has an thumbnail # Thumbnail: not every video has an thumbnail
mobj = re.search(r'<meta property="og:image" content="(?P<thumbnail>[^"]+)">', webpage) mobj = re.search(r'<meta property="og:image" content="(?P<thumbnail>[^"]+)">', webpage)
if mobj: if mobj:
video_thumbnail = mobj.group(u'thumbnail') video_thumbnail = mobj.group('thumbnail')
else: else:
video_thumbnail = None video_thumbnail = None
mobj = re.search(r'<filename [^>]+><!\[CDATA\[(?P<url>rtmpe://(?:[^/]+/){2})(?P<play_path>[^\]]+)\]\]></filename>', playerdata) mobj = re.search(r'<filename [^>]+><!\[CDATA\[(?P<url>rtmpe://(?:[^/]+/){2})(?P<play_path>[^\]]+)\]\]></filename>', playerdata)
if mobj is None: if mobj is None:
raise ExtractorError(u'Unable to extract media URL') raise ExtractorError('Unable to extract media URL')
video_url = mobj.group(u'url') video_url = mobj.group('url')
video_play_path = u'mp4:' + mobj.group(u'play_path') video_play_path = 'mp4:' + mobj.group('play_path')
video_player_url = video_page_url + u'includes/vodplayer.swf' video_player_url = video_page_url + 'includes/vodplayer.swf'
return [{ return {
'id': video_id, 'id': video_id,
'url': video_url, 'url': video_url,
'play_path': video_play_path, 'play_path': video_play_path,
@ -141,4 +145,4 @@ class RTLnowIE(InfoExtractor):
'description': video_description, 'description': video_description,
'upload_date': video_upload_date, 'upload_date': video_upload_date,
'thumbnail': video_thumbnail, 'thumbnail': video_thumbnail,
}] }