From f8661c6578d2b3cff1e064bc899b6e77c3d92966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 13 May 2020 22:35:33 +0200 Subject: [PATCH] [downloader:ytdl] fix file extensions when merging into mkv --- gallery_dl/downloader/ytdl.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gallery_dl/downloader/ytdl.py b/gallery_dl/downloader/ytdl.py index 8e60a0c5..335713f5 100644 --- a/gallery_dl/downloader/ytdl.py +++ b/gallery_dl/downloader/ytdl.py @@ -70,6 +70,10 @@ class YoutubeDLDownloader(DownloaderBase): if "url" in info_dict: text.nameext_from_url(info_dict["url"], pathfmt.kwdict) + formats = info_dict.get("requested_formats") + if formats and not compatible_formats(formats): + info_dict["ext"] = "mkv" + if self.outtmpl: self.ytdl.params["outtmpl"] = self.outtmpl pathfmt.filename = filename = self.ytdl.prepare_filename(info_dict) @@ -105,4 +109,15 @@ class YoutubeDLDownloader(DownloaderBase): return True +def compatible_formats(formats): + video_ext = formats[0].get("ext") + audio_ext = formats[1].get("ext") + + if video_ext == "webm" and audio_ext == "webm": + return True + + exts = ("mp3", "mp4", "m4a", "m4p", "m4b", "m4r", "m4v", "ismv", "isma") + return video_ext in exts and audio_ext in exts + + __downloader__ = YoutubeDLDownloader