Implement @dstftw review comments
This commit is contained in:
parent
13d2684263
commit
97c1053ba8
@ -1099,35 +1099,49 @@ 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'])
|
||||||
formats = []
|
title = (dict_get(media.get('headlines') or {},
|
||||||
keys = {'url', 'format', 'format_id', 'language', 'quality', 'tbr', 'resolution'}
|
('shortHeadline', 'headline'))
|
||||||
for format in playlist:
|
or playlist_title),
|
||||||
if not (format.get('url') and format.get('format')):
|
programme_id = media.get('id')
|
||||||
continue
|
if programme_id and title:
|
||||||
bitrate = format.pop('bitrate')
|
formats = []
|
||||||
if bitrate:
|
keys = {'url', 'format', 'format_id', 'language', 'quality', 'tbr', 'resolution'}
|
||||||
bitrate = re.sub(r'000\s*$', 'kbps', bitrate)
|
for format in playlist:
|
||||||
format['tbr'] = parse_bitrate(bitrate)
|
if not (format.get('url') and format.get('format')):
|
||||||
format['language'] = media.get('language')
|
continue
|
||||||
# format id: penultimate item from the url split on _ and .
|
bitrate = format.pop('bitrate')
|
||||||
(fmt,) = re.split('[_.]', format['url'])[-2:][:1]
|
format['tbr'] = int_or_none(bitrate, scale=1000) or parse_bitrate(bitrate)
|
||||||
format['format_id'] = '%s_%s' % (format['format'], fmt)
|
format['language'] = media.get('language')
|
||||||
if not format.get('resolution'):
|
# format id: penultimate item from the url split on _ and .
|
||||||
format['resolution'] = fmt
|
(fmt,) = re.split('[_.]', format['url'])[-2:][:1]
|
||||||
format['quality'] = -1
|
format['format_id'] = '%s_%s' % (format['format'], fmt)
|
||||||
formats.append(dict((k, format[k]) for k in keys))
|
# try to set resolution using any available data
|
||||||
self._sort_formats(formats)
|
aspect_ratio = re.split(r'[xX:]', media.get('aspectRatio') or '')
|
||||||
return {
|
if len(aspect_ratio) != 2:
|
||||||
'id': media.get('id'),
|
aspect_ratio = None
|
||||||
'title': (dict_get(media.get('headlines'),
|
else:
|
||||||
('shortHeadline', 'headline'))
|
aspect_ratio = float_or_none(aspect_ratio[0], scale=aspect_ratio[1])
|
||||||
or playlist_title),
|
# these may not be present, but try anyway
|
||||||
'description': media.get('summary') or playlist_description,
|
width = int_or_none(format.get('width'))
|
||||||
'formats': formats,
|
height = int_or_none(format.get('height'))
|
||||||
'subtitles': None,
|
if (not height) and aspect_ratio:
|
||||||
'thumbnail': try_get(media, lambda x: x['image']['href']),
|
height = int(width / aspect_ratio)
|
||||||
'timestamp': int_or_none(media.get('timestamp'), scale=1000)
|
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
|
||||||
|
formats.append(dict((k, format[k]) for k in keys))
|
||||||
|
self._sort_formats(formats)
|
||||||
|
return {
|
||||||
|
'id': programme_id,
|
||||||
|
'title': title,
|
||||||
|
'description': media.get('summary') or playlist_description,
|
||||||
|
'formats': formats,
|
||||||
|
'subtitles': None,
|
||||||
|
'thumbnail': try_get(media, lambda x: x['image']['href']),
|
||||||
|
'timestamp': int_or_none(media.get('timestamp'), scale=1000)
|
||||||
|
}
|
||||||
|
|
||||||
# general case: media nested in content object
|
# general case: media nested in content object
|
||||||
# test: https://www.bbc.co.uk/scotland/articles/cm49v4x1r9lo
|
# test: https://www.bbc.co.uk/scotland/articles/cm49v4x1r9lo
|
||||||
|
Loading…
Reference in New Issue
Block a user