mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 02:55:17 +00:00
[drbonanza] Fix extraction (closes #13231)
This commit is contained in:
parent
c56ad5c975
commit
87b5184a0d
1 changed files with 35 additions and 111 deletions
|
@ -1,135 +1,59 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
int_or_none,
|
js_to_json,
|
||||||
parse_iso8601,
|
parse_duration,
|
||||||
|
unescapeHTML,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DRBonanzaIE(InfoExtractor):
|
class DRBonanzaIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/(?:[^/]+/)+(?:[^/])+?(?:assetId=(?P<id>\d+))?(?:[#&]|$)'
|
_VALID_URL = r'https?://(?:www\.)?dr\.dk/bonanza/[^/]+/\d+/[^/]+/(?P<id>\d+)/(?P<display_id>[^/?#&]+)'
|
||||||
|
_TEST = {
|
||||||
_TESTS = [{
|
'url': 'http://www.dr.dk/bonanza/serie/154/matador/40312/matador---0824-komme-fremmede-',
|
||||||
'url': 'http://www.dr.dk/bonanza/serie/portraetter/Talkshowet.htm?assetId=65517',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '65517',
|
'id': '40312',
|
||||||
|
'display_id': 'matador---0824-komme-fremmede-',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Talkshowet - Leonard Cohen',
|
'title': 'MATADOR - 08:24. "Komme fremmede".',
|
||||||
'description': 'md5:8f34194fb30cd8c8a30ad8b27b70c0ca',
|
'description': 'md5:77b4c1ac4d4c1b9d610ab4395212ff84',
|
||||||
'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
|
'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
|
||||||
'timestamp': 1295537932,
|
'duration': 4613,
|
||||||
'upload_date': '20110120',
|
|
||||||
'duration': 3664,
|
|
||||||
},
|
},
|
||||||
'params': {
|
}
|
||||||
'skip_download': True, # requires rtmp
|
|
||||||
},
|
|
||||||
}, {
|
|
||||||
'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',
|
|
||||||
'thumbnail': r're:^https?://.*\.(?:gif|jpg)$',
|
|
||||||
'timestamp': 1223274900,
|
|
||||||
'upload_date': '20081006',
|
|
||||||
'duration': 7369,
|
|
||||||
},
|
|
||||||
}]
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
url_id = self._match_id(url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
webpage = self._download_webpage(url, url_id)
|
video_id, display_id = mobj.group('id', 'display_id')
|
||||||
|
|
||||||
if url_id:
|
webpage = self._download_webpage(url, display_id)
|
||||||
info = json.loads(self._html_search_regex(r'({.*?%s.*})' % 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'])
|
info = self._parse_html5_media_entries(
|
||||||
title = info['Title'].rstrip(' \'\"-,.:;!?')
|
url, webpage, display_id, m3u8_id='hls',
|
||||||
duration = int_or_none(info.get('Duration'), scale=1000)
|
m3u8_entry_protocol='m3u8_native')[0]
|
||||||
# First published online. "FirstPublished" contains the date for original airing.
|
self._sort_formats(info['formats'])
|
||||||
timestamp = parse_iso8601(
|
|
||||||
re.sub(r'\.\d+$', '', info['Created']))
|
|
||||||
|
|
||||||
def parse_filename_info(url):
|
asset = self._parse_json(
|
||||||
match = re.search(r'/\d+_(?P<width>\d+)x(?P<height>\d+)x(?P<bitrate>\d+)K\.(?P<ext>\w+)$', url)
|
self._search_regex(
|
||||||
if match:
|
r'(?s)currentAsset\s*=\s*({.+?})\s*</script', webpage, 'asset'),
|
||||||
return {
|
display_id, transform_source=js_to_json)
|
||||||
'width': int(match.group('width')),
|
|
||||||
'height': int(match.group('height')),
|
|
||||||
'vbr': int(match.group('bitrate')),
|
|
||||||
'ext': match.group('ext')
|
|
||||||
}
|
|
||||||
match = re.search(r'/\d+_(?P<bitrate>\d+)K\.(?P<ext>\w+)$', url)
|
|
||||||
if match:
|
|
||||||
return {
|
|
||||||
'vbr': int(match.group('bitrate')),
|
|
||||||
'ext': match.group(2)
|
|
||||||
}
|
|
||||||
return {}
|
|
||||||
|
|
||||||
video_types = ['VideoHigh', 'VideoMid', 'VideoLow']
|
title = unescapeHTML(asset['AssetTitle']).strip()
|
||||||
preferencemap = {
|
|
||||||
'VideoHigh': -1,
|
|
||||||
'VideoMid': -2,
|
|
||||||
'VideoLow': -3,
|
|
||||||
'Audio': -4,
|
|
||||||
}
|
|
||||||
|
|
||||||
formats = []
|
def extract(field):
|
||||||
for file in info['Files']:
|
return self._search_regex(
|
||||||
if info['Type'] == 'Video':
|
r'<div[^>]+>\s*<p>%s:<p>\s*</div>\s*<div[^>]+>\s*<p>([^<]+)</p>' % field,
|
||||||
if file['Type'] in video_types:
|
webpage, field, default=None)
|
||||||
format = parse_filename_info(file['Location'])
|
|
||||||
format.update({
|
|
||||||
'url': file['Location'],
|
|
||||||
'format_id': file['Type'].replace('Video', ''),
|
|
||||||
'preference': preferencemap.get(file['Type'], -10),
|
|
||||||
})
|
|
||||||
if format['url'].startswith('rtmp'):
|
|
||||||
rtmp_url = format['url']
|
|
||||||
format['rtmp_live'] = True # --resume does not work
|
|
||||||
if '/bonanza/' in rtmp_url:
|
|
||||||
format['play_path'] = rtmp_url.split('/bonanza/')[1]
|
|
||||||
formats.append(format)
|
|
||||||
elif file['Type'] == 'Thumb':
|
|
||||||
thumbnail = file['Location']
|
|
||||||
elif info['Type'] == 'Audio':
|
|
||||||
if file['Type'] == 'Audio':
|
|
||||||
format = parse_filename_info(file['Location'])
|
|
||||||
format.update({
|
|
||||||
'url': file['Location'],
|
|
||||||
'format_id': file['Type'],
|
|
||||||
'vcodec': 'none',
|
|
||||||
})
|
|
||||||
formats.append(format)
|
|
||||||
elif file['Type'] == 'Thumb':
|
|
||||||
thumbnail = file['Location']
|
|
||||||
|
|
||||||
description = '%s\n%s\n%s\n' % (
|
info.update({
|
||||||
info['Description'], info['Actors'], info['Colophon'])
|
'id': asset.get('AssetId') or video_id,
|
||||||
|
|
||||||
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,
|
|
||||||
'display_id': display_id,
|
'display_id': display_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'formats': formats,
|
'description': extract('Programinfo'),
|
||||||
'description': description,
|
'duration': parse_duration(extract('Tid')),
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': asset.get('AssetImageUrl'),
|
||||||
'timestamp': timestamp,
|
})
|
||||||
'duration': duration,
|
return info
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue