diff --git a/app/main.py b/app/main.py index dc63ce8..43dd3eb 100644 --- a/app/main.py +++ b/app/main.py @@ -56,7 +56,7 @@ class Config: 'PUBLIC_HOST_URL': 'download/', 'PUBLIC_HOST_AUDIO_URL': 'audio_download/', 'OUTPUT_TEMPLATE': '%(title)s.%(ext)s', - 'OUTPUT_TEMPLATE_CHAPTER': '%(title)s - %(section_number)s %(section_title)s.%(ext)s', + 'OUTPUT_TEMPLATE_CHAPTER': '%(title)s - %(section_number)02d - %(section_title)s.%(ext)s', 'OUTPUT_TEMPLATE_PLAYLIST': '%(playlist_title)s/%(title)s.%(ext)s', 'DEFAULT_OPTION_PLAYLIST_STRICT_MODE' : 'false', 'DEFAULT_OPTION_PLAYLIST_ITEM_LIMIT' : '0', @@ -261,7 +261,7 @@ async def add(request): if split_by_chapters is None: split_by_chapters = False if chapter_template is None: - chapter_template = '%(title)s - %(section_number)02d - %(section_title)s.%(ext)s' + chapter_template = config.OUTPUT_TEMPLATE_CHAPTER playlist_item_limit = int(playlist_item_limit) diff --git a/app/ytdl.py b/app/ytdl.py index f76e985..e88bcd5 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -462,7 +462,7 @@ class DownloadQueue: return {'status': 'ok'} return {'status': 'error', 'msg': f'Unsupported resource "{etype}"'} - async def add(self, url, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start=True, split_by_chapters=False, chapter_template='%(title)s - %(section_number)02d - %(section_title)s.%(ext)s', already=None): + async def add(self, url, quality, format, folder, custom_name_prefix, playlist_strict_mode, playlist_item_limit, auto_start=True, split_by_chapters=False, chapter_template=None, already=None): log.info(f'adding {url}: {quality=} {format=} {already=} {folder=} {custom_name_prefix=} {playlist_strict_mode=} {playlist_item_limit=} {auto_start=} {split_by_chapters=} {chapter_template=}') already = set() if already is None else already if url in already: diff --git a/ui/src/app/app.ts b/ui/src/app/app.ts index d8fdd89..7f7a959 100644 --- a/ui/src/app/app.ts +++ b/ui/src/app/app.ts @@ -106,7 +106,8 @@ export class App implements AfterViewInit, OnInit { this.quality = this.cookieService.get('metube_quality') || 'best'; this.autoStart = this.cookieService.get('metube_auto_start') !== 'false'; this.splitByChapters = this.cookieService.get('metube_split_chapters') === 'true'; - this.chapterTemplate = this.cookieService.get('metube_chapter_template') || '%(title)s - %(section_number)02d - %(section_title)s.%(ext)s'; + // Will be set from backend configuration, use empty string as placeholder + this.chapterTemplate = this.cookieService.get('metube_chapter_template') || ''; this.activeTheme = this.getPreferredTheme(this.cookieService); @@ -225,6 +226,10 @@ export class App implements AfterViewInit, OnInit { if (playlistItemLimit !== '0') { this.playlistItemLimit = playlistItemLimit; } + // Set chapter template from backend config if not already set by cookie + if (!this.chapterTemplate) { + this.chapterTemplate = config['OUTPUT_TEMPLATE_CHAPTER']; + } } }); } @@ -269,9 +274,9 @@ export class App implements AfterViewInit, OnInit { } chapterTemplateChanged() { - // Restore default if template is cleared + // Restore default if template is cleared - get from configuration if (!this.chapterTemplate || this.chapterTemplate.trim() === '') { - this.chapterTemplate = '%(title)s - %(section_number)02d - %(section_title)s.%(ext)s'; + this.chapterTemplate = this.downloads.configuration['OUTPUT_TEMPLATE_CHAPTER']; } this.cookieService.set('metube_chapter_template', this.chapterTemplate, { expires: 3650 }); } diff --git a/ui/src/app/services/downloads.service.ts b/ui/src/app/services/downloads.service.ts index 2590c7e..5a360f8 100644 --- a/ui/src/app/services/downloads.service.ts +++ b/ui/src/app/services/downloads.service.ts @@ -151,7 +151,7 @@ export class DownloadsService { const defaultPlaylistItemLimit = 0; const defaultAutoStart = true; const defaultSplitByChapters = false; - const defaultChapterTemplate = '%(title)s - %(section_number)02d - %(section_title)s.%(ext)s'; + const defaultChapterTemplate = this.configuration['OUTPUT_TEMPLATE_CHAPTER']; return new Promise((resolve, reject) => { this.add(url, defaultQuality, defaultFormat, defaultFolder, defaultCustomNamePrefix, defaultPlaylistStrictMode, defaultPlaylistItemLimit, defaultAutoStart, defaultSplitByChapters, defaultChapterTemplate)