From fc19010808ce8aa9a5330d50f3feaaa042bce7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 16 Jul 2021 02:14:59 +0200 Subject: [PATCH] [downloader:ytdl] fix 'outtmpl' setting for yt_dlp (#1680) yt_dlp supports multiple outtmpl settings for different file types and uses its 'outtmpl_dict' for that. --- gallery_dl/downloader/ytdl.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gallery_dl/downloader/ytdl.py b/gallery_dl/downloader/ytdl.py index 9a55dc91..543799d1 100644 --- a/gallery_dl/downloader/ytdl.py +++ b/gallery_dl/downloader/ytdl.py @@ -88,7 +88,7 @@ class YoutubeDLDownloader(DownloaderBase): info_dict["ext"] = "mkv" if self.outtmpl: - self.ytdl.params["outtmpl"] = self.outtmpl + self._set_outtmpl(self.outtmpl) pathfmt.filename = filename = self.ytdl.prepare_filename(info_dict) pathfmt.extension = info_dict["ext"] pathfmt.path = pathfmt.directory + filename @@ -103,7 +103,8 @@ class YoutubeDLDownloader(DownloaderBase): if self.part and self.partdir: pathfmt.temppath = os.path.join( self.partdir, pathfmt.filename) - self.ytdl.params["outtmpl"] = pathfmt.temppath.replace("%", "%%") + + self._set_outtmpl(pathfmt.temppath.replace("%", "%%")) self.out.start(pathfmt.path) try: @@ -115,12 +116,18 @@ class YoutubeDLDownloader(DownloaderBase): def _download_playlist(self, pathfmt, info_dict): pathfmt.set_extension("%(playlist_index)s.%(ext)s") - self.ytdl.params["outtmpl"] = pathfmt.realpath + self._set_outtmpl(pathfmt.realpath) for entry in info_dict["entries"]: self.ytdl.process_info(entry) return True + def _set_outtmpl(self, outtmpl): + try: + self.ytdl.outtmpl_dict["default"] = outtmpl + except AttributeError: + self.ytdl.params["outtmpl"] = outtmpl + def compatible_formats(formats): """Returns True if 'formats' are compatible for merge"""