aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Shnitman <alexta69@gmail.com>2022-06-19 21:54:30 +0300
committerAlex Shnitman <alexta69@gmail.com>2022-06-19 21:54:30 +0300
commit566774316fdccf4e89f9bd4f1a0faae73ebe6a4a (patch)
tree9f036a8b5553380a830f6542232308dfd51fe11b
parenttypo `Warning` (diff)
parentMerge pull request #149 from georgekav2/master (diff)
downloadmetube-566774316fdccf4e89f9bd4f1a0faae73ebe6a4a.tar.gz
metube-566774316fdccf4e89f9bd4f1a0faae73ebe6a4a.tar.bz2
metube-566774316fdccf4e89f9bd4f1a0faae73ebe6a4a.zip
Merge branch 'master' of https://github.com/alexta69/metube into VergilGao/master
-rw-r--r--README.md1
-rw-r--r--app/main.py1
-rw-r--r--app/ytdl.py11
3 files changed, 9 insertions, 4 deletions
diff --git a/README.md b/README.md
index 78ac98e..5b32f90 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,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:
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 38e29b8..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
@@ -72,7 +73,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, "chapter": self.output_template_chapter },
'format': self.format,
'cachedir': False,
'socket_timeout': 30,
@@ -146,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
@@ -227,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'}
bgstack15