From b5f1fcb5f99086f99bdfe5c19d238794c0334da9 Mon Sep 17 00:00:00 2001 From: Adebimpe51 Date: Thu, 13 Mar 2025 10:06:36 +0100 Subject: [PATCH] Fix KeyError('50') in Google Drive extractor by adding safe extension lookup --- youtube_dl/extractor/googledrive.py | 40 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/youtube_dl/extractor/googledrive.py b/youtube_dl/extractor/googledrive.py index 3f2de00f1..81c95a7f9 100644 --- a/youtube_dl/extractor/googledrive.py +++ b/youtube_dl/extractor/googledrive.py @@ -187,23 +187,29 @@ class GoogleDriveIE(InfoExtractor): resolutions[mobj.group('format_id')] = ( int(mobj.group('width')), int(mobj.group('height'))) - for fmt_stream in fmt_stream_map: - fmt_stream_split = fmt_stream.split('|') - if len(fmt_stream_split) < 2: - continue - format_id, format_url = fmt_stream_split[:2] - f = { - 'url': lowercase_escape(format_url), - 'format_id': format_id, - 'ext': self._FORMATS_EXT[format_id], - } - resolution = resolutions.get(format_id) - if resolution: - f.update({ - 'width': resolution[0], - 'height': resolution[1], - }) - formats.append(f) + for fmt_stream in fmt_stream_map: + fmt_stream_split = fmt_stream.split('|') + if len(fmt_stream_split) < 2: + continue + format_id, format_url = fmt_stream_split[:2] + # Try to get the extension from the known formats + ext = self._FORMATS_EXT.get(format_id) + # Fallback: Determine extension from the URL (defaulting to 'mp4' if not found) + if not ext: + ext = determine_ext(format_url, 'mp4').lower() + f = { + 'url': lowercase_escape(format_url), + 'format_id': format_id, + 'ext': ext, + } + resolution = resolutions.get(format_id) + if resolution: + f.update({ + 'width': resolution[0], + 'height': resolution[1], + }) + formats.append(f) + source_url = update_url_query( 'https://drive.google.com/uc', {