From 8283716547570dba2e6a7da92aa8457fad2366e2 Mon Sep 17 00:00:00 2001 From: guahki Date: Sun, 16 Apr 2023 13:07:25 +0200 Subject: [PATCH] Introduce DELETE_FILE_ON_TRASHCAN option, to delete files on the server --- README.md | 1 + app/main.py | 3 ++- app/ytdl.py | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b83713e..2accf35 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Certain values can be set via environment variables, using the `-e` parameter on * __CUSTOM_DIRS__: whether to enable downloading videos into custom directories within the __DOWNLOAD_DIR__ (or __AUDIO_DOWNLOAD_DIR__). When enabled, a drop-down appears next to the Add button to specify the download directory. Defaults to `true`. * __CREATE_CUSTOM_DIRS__: whether to support automatically creating directories within the __DOWNLOAD_DIR__ (or __AUDIO_DOWNLOAD_DIR__) if they do not exist. When enabled, the download directory selector becomes supports free-text input, and the specified directory will be created recursively. Defaults to `true`. * __STATE_DIR__: path to where the queue persistence files will be saved. Defaults to `/downloads/.metube` in the docker image, and `.` otherwise. +* __DELETE_FILE_ON_TRASHCAN__: if `true`, downloaded files are deleted on the server, when they are trashed from the "Completed" section of the UI. Defaults to `false`. * __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`. diff --git a/app/main.py b/app/main.py index d59b7c1..05fb7d2 100644 --- a/app/main.py +++ b/app/main.py @@ -19,6 +19,7 @@ class Config: 'AUDIO_DOWNLOAD_DIR': '%%DOWNLOAD_DIR', 'CUSTOM_DIRS': 'true', 'CREATE_CUSTOM_DIRS': 'true', + 'DELETE_FILE_ON_TRASHCAN': 'false', 'STATE_DIR': '.', 'URL_PREFIX': '', 'OUTPUT_TEMPLATE': '%(title)s.%(ext)s', @@ -29,7 +30,7 @@ class Config: 'BASE_DIR': '' } - _BOOLEAN = ('CUSTOM_DIRS', 'CREATE_CUSTOM_DIRS') + _BOOLEAN = ('CUSTOM_DIRS', 'CREATE_CUSTOM_DIRS', 'DELETE_FILE_ON_TRASHCAN') def __init__(self): for k, v in self._DEFAULTS.items(): diff --git a/app/ytdl.py b/app/ytdl.py index 75462e4..f4f1709 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -292,6 +292,9 @@ class DownloadQueue: if not self.done.exists(id): log.warn(f'requested delete for non-existent download {id}') continue + if self.config.DELETE_FILE_ON_TRASHCAN: + dl = self.done.get(id) + os.remove(os.path.join(dl.download_dir, dl.info.filename)) self.done.delete(id) await self.notifier.cleared(id) return {'status': 'ok'}