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.
This commit is contained in:
parent
2e6658ce49
commit
712dc4ddbb
|
|
@ -19,6 +19,7 @@ class Config:
|
||||||
'STATE_DIR': '.',
|
'STATE_DIR': '.',
|
||||||
'URL_PREFIX': '',
|
'URL_PREFIX': '',
|
||||||
'OUTPUT_TEMPLATE': '%(title)s.%(ext)s',
|
'OUTPUT_TEMPLATE': '%(title)s.%(ext)s',
|
||||||
|
'OUTPUT_TEMPLATE_CHAPTER': '%(title)s - %(section_number)s %(section_title)s.%(ext)s',
|
||||||
'YTDL_OPTIONS': '{}',
|
'YTDL_OPTIONS': '{}',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
app/ytdl.py
10
app/ytdl.py
|
|
@ -38,9 +38,10 @@ class DownloadInfo:
|
||||||
class Download:
|
class Download:
|
||||||
manager = None
|
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.download_dir = download_dir
|
||||||
self.output_template = output_template
|
self.output_template = output_template
|
||||||
|
self.output_template_chapter = output_template_chapter
|
||||||
self.format = get_format(format, quality)
|
self.format = get_format(format, quality)
|
||||||
self.ytdl_opts = get_opts(format, quality, ytdl_opts)
|
self.ytdl_opts = get_opts(format, quality, ytdl_opts)
|
||||||
self.info = info
|
self.info = info
|
||||||
|
|
@ -73,7 +74,7 @@ class Download:
|
||||||
'no_color': True,
|
'no_color': True,
|
||||||
#'skip_download': True,
|
#'skip_download': True,
|
||||||
'paths': {"home": self.download_dir},
|
'paths': {"home": self.download_dir},
|
||||||
'outtmpl': { "default": self.output_template},
|
'outtmpl': { "default": self.output_template, "chapter": self.output_template_chapter },
|
||||||
'format': self.format,
|
'format': self.format,
|
||||||
'cachedir': False,
|
'cachedir': False,
|
||||||
'socket_timeout': 30,
|
'socket_timeout': 30,
|
||||||
|
|
@ -147,7 +148,7 @@ class PersistentQueue:
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
for k, v in self.saved_items():
|
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):
|
def exists(self, key):
|
||||||
return key in self.dict
|
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)
|
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
|
dldirectory = self.config.DOWNLOAD_DIR if (quality != 'audio' and format != 'mp3') else self.config.AUDIO_DOWNLOAD_DIR
|
||||||
output = self.config.OUTPUT_TEMPLATE
|
output = self.config.OUTPUT_TEMPLATE
|
||||||
|
output_chapter = self.config.OUTPUT_TEMPLATE_CHAPTER
|
||||||
for property, value in entry.items():
|
for property, value in entry.items():
|
||||||
if property.startswith("playlist"):
|
if property.startswith("playlist"):
|
||||||
output = output.replace(f"%({property})s", str(value))
|
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()
|
self.event.set()
|
||||||
await self.notifier.added(dl)
|
await self.notifier.added(dl)
|
||||||
return {'status': 'ok'}
|
return {'status': 'ok'}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue