mirror of
https://github.com/alexta69/metube.git
synced 2026-09-21 13:35:01 +00:00
feat: DEFAULT_FOLDER pre-selects a download folder (closes #875)
Most downloads from a given install land in the same custom directory, which today means picking it by hand every time. DEFAULT_FOLDER seeds the folder field once the configuration arrives; the field stays editable, so per-download folders still work, and a folder already typed this session is not overwritten. The value is trimmed of surrounding slashes, and dropped with a warning when CUSTOM_DIRS is off, since the UI hides the field in that mode and the download path check rejects a folder anyway. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+14
@@ -62,6 +62,7 @@ class Config:
|
||||
'CUSTOM_DIRS': 'true',
|
||||
'CREATE_CUSTOM_DIRS': 'true',
|
||||
'CUSTOM_DIRS_EXCLUDE_REGEX': r'(^|/)[.@].*$',
|
||||
'DEFAULT_FOLDER': '',
|
||||
'DELETE_FILE_ON_TRASHCAN': 'false',
|
||||
'STATE_DIR': '.',
|
||||
'URL_PREFIX': '',
|
||||
@@ -127,6 +128,18 @@ class Config:
|
||||
if val and not val.endswith('/'):
|
||||
setattr(self, attr, val + '/')
|
||||
|
||||
# DEFAULT_FOLDER only pre-fills the form's folder field, which the UI
|
||||
# does not even show without CUSTOM_DIRS. Sending one anyway would fail
|
||||
# every download on the server's own folder check, so drop it and say so
|
||||
# rather than leaving the user with a form that cannot submit.
|
||||
self.DEFAULT_FOLDER = self.DEFAULT_FOLDER.strip().strip('/')
|
||||
if self.DEFAULT_FOLDER and not self.CUSTOM_DIRS:
|
||||
log.warning(
|
||||
'Ignoring DEFAULT_FOLDER "%s" because CUSTOM_DIRS is not enabled',
|
||||
self.DEFAULT_FOLDER,
|
||||
)
|
||||
self.DEFAULT_FOLDER = ''
|
||||
|
||||
# Convert relative addresses to absolute addresses to prevent the failure of file address comparison
|
||||
if self.YTDL_OPTIONS_FILE and self.YTDL_OPTIONS_FILE.startswith('.'):
|
||||
self.YTDL_OPTIONS_FILE = str(Path(self.YTDL_OPTIONS_FILE).resolve())
|
||||
@@ -187,6 +200,7 @@ class Config:
|
||||
_FRONTEND_KEYS = (
|
||||
'CUSTOM_DIRS',
|
||||
'CREATE_CUSTOM_DIRS',
|
||||
'DEFAULT_FOLDER',
|
||||
'OUTPUT_TEMPLATE_CHAPTER',
|
||||
'PUBLIC_HOST_URL',
|
||||
'PUBLIC_HOST_AUDIO_URL',
|
||||
|
||||
@@ -115,6 +115,28 @@ class ConfigTests(unittest.TestCase):
|
||||
self.assertNotIn("HOST", safe)
|
||||
self.assertEqual(safe["ALLOW_YTDL_OPTIONS_OVERRIDES"], False)
|
||||
|
||||
def test_default_folder_empty_by_default(self):
|
||||
with patch.dict(os.environ, _base_env(), clear=False):
|
||||
c = Config()
|
||||
self.assertEqual(c.DEFAULT_FOLDER, "")
|
||||
|
||||
def test_default_folder_is_trimmed_and_reaches_the_frontend(self):
|
||||
with patch.dict(os.environ, _base_env(DEFAULT_FOLDER=" /youtube/ "), clear=False):
|
||||
c = Config()
|
||||
self.assertEqual(c.DEFAULT_FOLDER, "youtube")
|
||||
self.assertEqual(c.frontend_safe()["DEFAULT_FOLDER"], "youtube")
|
||||
|
||||
def test_default_folder_ignored_without_custom_dirs(self):
|
||||
# The folder field is not shown at all without CUSTOM_DIRS, and sending
|
||||
# a folder anyway is rejected by the download path check.
|
||||
with patch.dict(
|
||||
os.environ,
|
||||
_base_env(DEFAULT_FOLDER="youtube", CUSTOM_DIRS="false"),
|
||||
clear=False,
|
||||
):
|
||||
c = Config()
|
||||
self.assertEqual(c.DEFAULT_FOLDER, "")
|
||||
|
||||
def test_allow_ytdl_options_overrides_boolean_loaded(self):
|
||||
with patch.dict(os.environ, _base_env(ALLOW_YTDL_OPTIONS_OVERRIDES="true"), clear=False):
|
||||
c = Config()
|
||||
|
||||
Reference in New Issue
Block a user