0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-27 03:03:01 +00:00

[googledrive] Fix formats' sorting (closes #13443)

This commit is contained in:
Sergey M․ 2017-06-20 22:58:33 +07:00
parent 048b55804d
commit 9be9ec5980
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -69,19 +69,32 @@ def _real_extract(self, url):
r'"fmt_stream_map"\s*,\s*"([^"]+)', webpage, 'fmt stream map').split(',') r'"fmt_stream_map"\s*,\s*"([^"]+)', webpage, 'fmt stream map').split(',')
fmt_list = self._search_regex(r'"fmt_list"\s*,\s*"([^"]+)', webpage, 'fmt_list').split(',') fmt_list = self._search_regex(r'"fmt_list"\s*,\s*"([^"]+)', webpage, 'fmt_list').split(',')
resolutions = {}
for fmt in fmt_list:
mobj = re.search(
r'^(?P<format_id>\d+)/(?P<width>\d+)[xX](?P<height>\d+)', fmt)
if mobj:
resolutions[mobj.group('format_id')] = (
int(mobj.group('width')), int(mobj.group('height')))
formats = [] formats = []
for fmt, fmt_stream in zip(fmt_list, fmt_stream_map): for fmt_stream in fmt_stream_map:
fmt_id, fmt_url = fmt_stream.split('|') fmt_stream_split = fmt_stream.split('|')
resolution = fmt.split('/')[1] if len(fmt_stream_split) < 2:
width, height = resolution.split('x') continue
formats.append({ format_id, format_url = fmt_stream_split[:2]
'url': lowercase_escape(fmt_url), f = {
'format_id': fmt_id, 'url': lowercase_escape(format_url),
'resolution': resolution, 'format_id': format_id,
'width': int_or_none(width), 'ext': self._FORMATS_EXT[format_id],
'height': int_or_none(height), }
'ext': self._FORMATS_EXT[fmt_id], resolution = resolutions.get(format_id)
}) if resolution:
f.update({
'width': resolution[0],
'height': resolution[0],
})
formats.append(f)
self._sort_formats(formats) self._sort_formats(formats)
return { return {