X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fdrbonanza.py;h=164e97c36b8cab223ac813abaa1f032eb7d4444a;hb=384bf91f8802805283f993714ace137e831ba45e;hp=8cbdb57b376d95cf4e0983e6d5418895d1fce991;hpb=8e7a9016d5e79679f4b948f00c794b8ff31a41e4;p=youtube-dl diff --git a/youtube_dl/extractor/drbonanza.py b/youtube_dl/extractor/drbonanza.py index 8cbdb57b3..164e97c36 100644 --- a/youtube_dl/extractor/drbonanza.py +++ b/youtube_dl/extractor/drbonanza.py @@ -1,120 +1,59 @@ from __future__ import unicode_literals -from .common import InfoExtractor -from .common import ExtractorError -from ..utils import parse_iso8601 -import json import re -class DRBonanzaIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/(?:[^/]+/)+(?:[^/])+?(?:assetId=(?P\d+))?(?:[#&]|$)' +from .common import InfoExtractor +from ..utils import ( + js_to_json, + parse_duration, + unescapeHTML, +) - _TESTS = [{ - 'url': 'http://www.dr.dk/bonanza/serie/portraetter/Talkshowet.htm?assetId=65517', - 'md5': 'fe330252ddea607635cf2eb2c99a0af3', + +class DRBonanzaIE(InfoExtractor): + _VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/[^/]+/\d+/[^/]+/(?P\d+)/(?P[^/?#&]+)' + _TEST = { + 'url': 'http://www.dr.dk/bonanza/serie/154/matador/40312/matador---0824-komme-fremmede-', 'info_dict': { - 'id': '65517', + 'id': '40312', + 'display_id': 'matador---0824-komme-fremmede-', 'ext': 'mp4', - 'title': 'Talkshowet - Leonard Cohen', - 'description': 'md5:8f34194fb30cd8c8a30ad8b27b70c0ca', - 'timestamp': 1295537932, - 'upload_date': '20110120', - 'duration': 3664000, - }, - },{ - 'url': 'http://www.dr.dk/bonanza/radio/serie/sport/fodbold.htm?assetId=59410', - 'md5': '6dfe039417e76795fb783c52da3de11d', - 'info_dict': { - 'id': '59410', - 'ext': 'mp3', - 'title': 'EM fodbold 1992 Danmark - Tyskland finale Transmission', - 'description': 'md5:501e5a195749480552e214fbbed16c4e', - 'timestamp': 1223274900, - 'upload_date': '20081006', - 'duration': 7369000, + 'title': 'MATADOR - 08:24. "Komme fremmede".', + 'description': 'md5:77b4c1ac4d4c1b9d610ab4395212ff84', + 'thumbnail': r're:^https?://.*\.(?:gif|jpg)$', + 'duration': 4613, }, - }] + } def _real_extract(self, url): - url_id = self._match_id(url) - - webpage = self._download_webpage(url, url_id if url_id else "") - - if url_id: - info = json.loads(self._html_search_regex(r'({.*?' + url_id + '.*})', webpage, 'json')) - else: - # Just fetch the first video on that page - info = json.loads(self._html_search_regex(r'bonanzaFunctions.newPlaylist\(({.*})\)', webpage, 'json')) - - asset_id = str(info['AssetId']) - title = info['Title'].rstrip(' \'\"-,.:;!?') - duration = info['Duration'] - timestamp = parse_iso8601(re.sub(r'\.\d+$', '', info['Created'])) # First published online. "FirstPublished" contains the date for original airing. - - def parse_filename_info(url): - match = re.search(r'/\d+_(?P\d+)x(?P\d+)x(?P\d+)K\.(?P\w+)$', url) - if match: - return {'width': int(match.group(1)), 'height': int(match.group(2)), 'bitrate': int(match.group(3)), 'ext': match.group(4)} - match = re.search(r'/\d+_(?P\d+)K\.(?P\w+)$', url) - if match: - return {'bitrate': int(match.group(1)), 'ext': match.group(2)} - return {'width': None, 'height': None, 'bitrate': None, 'ext': None} - - video_types = ['VideoHigh', 'VideoMid', 'VideoLow'] - preferencemap = { - 'VideoHigh': -1, - 'VideoMid': -2, - 'VideoLow': -3, - 'Audio': -4, - } - - formats = [] - for file in info['Files']: - if info['Type'] == "Video": - if file['Type'] in video_types: - fileinfo = parse_filename_info(file['Location']) - formats.append({ - 'url': file['Location'], - 'format_id': file['Type'].replace('Video', ''), - 'preference': preferencemap.get(file['Type'], -10), - 'width': fileinfo['width'], - 'height': fileinfo['height'], - 'vbr': fileinfo['bitrate'], - 'ext': fileinfo['ext'], - }) - elif file['Type'] == "Thumb": - thumbnail = file['Location'] - elif info['Type'] == "Audio": - if file['Type'] == "Audio": - fileinfo = parse_filename_info(file['Location']) - formats.append({ - 'url': file['Location'], - 'format_id': file['Type'], - 'abr': fileinfo['bitrate'], - 'ext': fileinfo['ext'], - 'vcodec': 'none', - }) - elif file['Type'] == "Thumb": - thumbnail = file['Location'] - - description = "{}\n{}\n{}\n".format(info['Description'], info['Actors'], info['Colophon']) + mobj = re.match(self._VALID_URL, url) + video_id, display_id = mobj.group('id', 'display_id') + + webpage = self._download_webpage(url, display_id) + + info = self._parse_html5_media_entries( + url, webpage, display_id, m3u8_id='hls', + m3u8_entry_protocol='m3u8_native')[0] + self._sort_formats(info['formats']) + + asset = self._parse_json( + self._search_regex( + r'(?s)currentAsset\s*=\s*({.+?})\s*]+>\s*

%s:

\s*\s*]+>\s*

([^<]+)

' % field, + webpage, field, default=None) - for f in formats: - f['url'] = f['url'].replace('rtmp://vod-bonanza.gss.dr.dk/bonanza/', 'http://vodfiles.dr.dk/') - f['url'] = f['url'].replace('mp4:bonanza', 'bonanza') - - self._sort_formats(formats) - - display_id = re.sub(r'[^\w\d-]', '', re.sub(r' ', '-', title.lower())) + '-' + asset_id - display_id = re.sub(r'-+', '-', display_id) - - return { - 'id': asset_id, + info.update({ + 'id': asset.get('AssetId') or video_id, 'display_id': display_id, 'title': title, - 'formats': formats, - 'description': description, - 'thumbnail': thumbnail, - 'timestamp': timestamp, - 'duration': duration, - } + 'description': extract('Programinfo'), + 'duration': parse_duration(extract('Tid')), + 'thumbnail': asset.get('AssetImageUrl'), + }) + return info