mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 16:45:51 +00:00
Implement @dstftw review comments
This commit is contained in:
parent
13d2684263
commit
97c1053ba8
1 changed files with 43 additions and 29 deletions
|
@ -1099,29 +1099,43 @@ class BBCIE(BBCCoUkIE):
|
||||||
media = simorgh_data['pageData']['promo']
|
media = simorgh_data['pageData']['promo']
|
||||||
if media['media'].get('format') == 'video':
|
if media['media'].get('format') == 'video':
|
||||||
media.update(media['media'])
|
media.update(media['media'])
|
||||||
|
title = (dict_get(media.get('headlines') or {},
|
||||||
|
('shortHeadline', 'headline'))
|
||||||
|
or playlist_title),
|
||||||
|
programme_id = media.get('id')
|
||||||
|
if programme_id and title:
|
||||||
formats = []
|
formats = []
|
||||||
keys = {'url', 'format', 'format_id', 'language', 'quality', 'tbr', 'resolution'}
|
keys = {'url', 'format', 'format_id', 'language', 'quality', 'tbr', 'resolution'}
|
||||||
for format in playlist:
|
for format in playlist:
|
||||||
if not (format.get('url') and format.get('format')):
|
if not (format.get('url') and format.get('format')):
|
||||||
continue
|
continue
|
||||||
bitrate = format.pop('bitrate')
|
bitrate = format.pop('bitrate')
|
||||||
if bitrate:
|
format['tbr'] = int_or_none(bitrate, scale=1000) or parse_bitrate(bitrate)
|
||||||
bitrate = re.sub(r'000\s*$', 'kbps', bitrate)
|
|
||||||
format['tbr'] = parse_bitrate(bitrate)
|
|
||||||
format['language'] = media.get('language')
|
format['language'] = media.get('language')
|
||||||
# format id: penultimate item from the url split on _ and .
|
# format id: penultimate item from the url split on _ and .
|
||||||
(fmt,) = re.split('[_.]', format['url'])[-2:][:1]
|
(fmt,) = re.split('[_.]', format['url'])[-2:][:1]
|
||||||
format['format_id'] = '%s_%s' % (format['format'], fmt)
|
format['format_id'] = '%s_%s' % (format['format'], fmt)
|
||||||
if not format.get('resolution'):
|
# try to set resolution using any available data
|
||||||
format['resolution'] = fmt
|
aspect_ratio = re.split(r'[xX:]', media.get('aspectRatio') or '')
|
||||||
|
if len(aspect_ratio) != 2:
|
||||||
|
aspect_ratio = None
|
||||||
|
else:
|
||||||
|
aspect_ratio = float_or_none(aspect_ratio[0], scale=aspect_ratio[1])
|
||||||
|
# these may not be present, but try anyway
|
||||||
|
width = int_or_none(format.get('width'))
|
||||||
|
height = int_or_none(format.get('height'))
|
||||||
|
if (not height) and aspect_ratio:
|
||||||
|
height = int(width / aspect_ratio)
|
||||||
|
elif (not width) and aspect_ratio:
|
||||||
|
width = int(height * aspect_ratio)
|
||||||
|
format['resolution'] = ('%dx%d' % (width, height) if width and height
|
||||||
|
else dict_get(format, ('resolution', 'res'), default=fmt))
|
||||||
format['quality'] = -1
|
format['quality'] = -1
|
||||||
formats.append(dict((k, format[k]) for k in keys))
|
formats.append(dict((k, format[k]) for k in keys))
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
return {
|
return {
|
||||||
'id': media.get('id'),
|
'id': programme_id,
|
||||||
'title': (dict_get(media.get('headlines'),
|
'title': title,
|
||||||
('shortHeadline', 'headline'))
|
|
||||||
or playlist_title),
|
|
||||||
'description': media.get('summary') or playlist_description,
|
'description': media.get('summary') or playlist_description,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'subtitles': None,
|
'subtitles': None,
|
||||||
|
|
Loading…
Reference in a new issue