From 2e6658ce4901d6d0a443235d0fe4b4d15f2a78e0 Mon Sep 17 00:00:00 2001 From: georgekav <> Date: Mon, 6 Jun 2022 20:46:29 +0200 Subject: Use paths parameters from yt_dlp for passing the path instead of making it part of the output template. This allows to use postprocessors like split-chapters that use their own output template parameter key ("chapter") and not the default one. By providing paths dictionary the postprocessors will respect that path for the output of the processed files. --- app/ytdl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/ytdl.py b/app/ytdl.py index 38e29b8..0128329 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -72,7 +72,8 @@ class Download: 'quiet': True, 'no_color': True, #'skip_download': True, - 'outtmpl': os.path.join(self.download_dir, self.output_template), + 'paths': {"home": self.download_dir}, + 'outtmpl': { "default": self.output_template}, 'format': self.format, 'cachedir': False, 'socket_timeout': 30, -- cgit From 712dc4ddbbb1d4d172f5f00d75a1cae33d45c09f Mon Sep 17 00:00:00 2001 From: georgekav <> Date: Mon, 6 Jun 2022 20:47:13 +0200 Subject: Pass to yt_dlp a chapter-specific output template When a FFmpegSplitChapters postprocessor is used it is taken into account, in all other cases the default output template is used. --- app/main.py | 1 + app/ytdl.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index 36c0e94..9fbdf19 100644 --- a/app/main.py +++ b/app/main.py @@ -19,6 +19,7 @@ class Config: 'STATE_DIR': '.', 'URL_PREFIX': '', 'OUTPUT_TEMPLATE': '%(title)s.%(ext)s', + 'OUTPUT_TEMPLATE_CHAPTER': '%(title)s - %(section_number)s %(section_title)s.%(ext)s', 'YTDL_OPTIONS': '{}', } diff --git a/app/ytdl.py b/app/ytdl.py index 0128329..21b82da 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -38,9 +38,10 @@ class DownloadInfo: class Download: manager = None - def __init__(self, download_dir, output_template, quality, format, ytdl_opts, info): + def __init__(self, download_dir, output_template, output_template_chapter, quality, format, ytdl_opts, info): self.download_dir = download_dir self.output_template = output_template + self.output_template_chapter = output_template_chapter self.format = get_format(format, quality) self.ytdl_opts = get_opts(format, quality, ytdl_opts) self.info = info @@ -73,7 +74,7 @@ class Download: 'no_color': True, #'skip_download': True, 'paths': {"home": self.download_dir}, - 'outtmpl': { "default": self.output_template}, + 'outtmpl': { "default": self.output_template, "chapter": self.output_template_chapter }, 'format': self.format, 'cachedir': False, 'socket_timeout': 30, @@ -147,7 +148,7 @@ class PersistentQueue: def load(self): for k, v in self.saved_items(): - self.dict[k] = Download(None, None, None, None, {}, v) + self.dict[k] = Download(None, None, None, None, None, {}, v) def exists(self, key): return key in self.dict @@ -228,10 +229,11 @@ class DownloadQueue: dl = DownloadInfo(entry['id'], entry['title'], entry.get('webpage_url') or entry['url'], quality, format) dldirectory = self.config.DOWNLOAD_DIR if (quality != 'audio' and format != 'mp3') else self.config.AUDIO_DOWNLOAD_DIR output = self.config.OUTPUT_TEMPLATE + output_chapter = self.config.OUTPUT_TEMPLATE_CHAPTER for property, value in entry.items(): if property.startswith("playlist"): output = output.replace(f"%({property})s", str(value)) - self.queue.put(Download(dldirectory, output, quality, format, self.config.YTDL_OPTIONS, dl)) + self.queue.put(Download(dldirectory, output, output_chapter, quality, format, self.config.YTDL_OPTIONS, dl)) self.event.set() await self.notifier.added(dl) return {'status': 'ok'} -- cgit From 38a911f489640b272e05b80b97b5262dd25f53d8 Mon Sep 17 00:00:00 2001 From: Alex Shnitman Date: Sun, 19 Jun 2022 21:51:10 +0300 Subject: added note about the OUTPUT_TEMPLATE_CHAPTER config variable to the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6d2562b..b1cade6 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Certain values can be set via environment variables, using the `-e` parameter on * __STATE_DIR__: path to where the queue persistence files will be saved. Defaults to `/downloads/.metube` in the docker image, and `.` otherwise. * __URL_PREFIX__: base path for the web server (for use when hosting behind a reverse proxy). Defaults to `/`. * __OUTPUT_TEMPLATE__: the template for the filenames of the downloaded videos, formatted according to [this spec](https://github.com/yt-dlp/yt-dlp/blob/master/README.md#output-template). Defaults to `%(title)s.%(ext)s`. +* __OUTPUT_TEMPLATE_CHAPTER__: the template for the filenames of the downloaded videos, when split into chapters via postprocessors. Defaults to `%(title)s - %(section_number)s %(section_title)s.%(ext)s`. * __YTDL_OPTIONS__: Additional options to pass to youtube-dl, in JSON format. [See available options here](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L176). They roughly correspond to command-line options, though some do not have exact equivalents here, for example `--recode-video` has to be specified via `postprocessors`. Also note that dashes are replaced with underscores. The following example value for `YTDL_OPTIONS` embeds English subtitles and chapter markers (for videos that have them), and also changes the permissions on the downloaded video: -- cgit