aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Shnitman <alexta69@gmail.com>2023-02-04 11:09:36 +0200
committerAlex Shnitman <alexta69@gmail.com>2023-02-04 11:09:36 +0200
commitea7a7b07113362718687dfbc778ae35323498e01 (patch)
treee46c3470576ddbe13261fb68fdcbfe27d621d90d /app
parentMerge pull request #216 from kaytwo/master (diff)
downloadmetube-ea7a7b07113362718687dfbc778ae35323498e01.tar.gz
metube-ea7a7b07113362718687dfbc778ae35323498e01.tar.bz2
metube-ea7a7b07113362718687dfbc778ae35323498e01.zip
Fix boolean env variables (closes #213)
Diffstat (limited to 'app')
-rw-r--r--app/main.py7
-rw-r--r--app/ytdl.py4
2 files changed, 9 insertions, 2 deletions
diff --git a/app/main.py b/app/main.py
index 27fc2b7..46f4424 100644
--- a/app/main.py
+++ b/app/main.py
@@ -26,12 +26,19 @@ class Config:
'YTDL_OPTIONS': '{}',
}
+ _BOOLEAN = ('CUSTOM_DIRS', 'CREATE_CUSTOM_DIRS')
+
def __init__(self):
for k, v in self._DEFAULTS.items():
setattr(self, k, os.environ[k] if k in os.environ else v)
for k, v in self.__dict__.items():
if v.startswith('%%'):
setattr(self, k, getattr(self, v[2:]))
+ if k in self._BOOLEAN:
+ if v not in ('true', 'false', 'True', 'False', 'on', 'off', '1', '0'):
+ log.error(f'Environment variable "{k}" is set to a non-boolean value "{v}"')
+ sys.exit(1)
+ setattr(self, k, v in ('true', 'True', 'on', '1'))
if not self.URL_PREFIX.endswith('/'):
self.URL_PREFIX += '/'
try:
diff --git a/app/ytdl.py b/app/ytdl.py
index 266de10..0a74b14 100644
--- a/app/ytdl.py
+++ b/app/ytdl.py
@@ -236,14 +236,14 @@ class DownloadQueue:
# Keep consistent with frontend
base_directory = self.config.DOWNLOAD_DIR if (quality != 'audio' and format != 'mp3') else self.config.AUDIO_DOWNLOAD_DIR
if folder:
- if self.config.CUSTOM_DIRS != 'true':
+ if not self.config.CUSTOM_DIRS:
return {'status': 'error', 'msg': f'A folder for the download was specified but CUSTOM_DIRS is not true in the configuration.'}
dldirectory = os.path.realpath(os.path.join(base_directory, folder))
real_base_directory = os.path.realpath(base_directory)
if not dldirectory.startswith(real_base_directory):
return {'status': 'error', 'msg': f'Folder "{folder}" must resolve inside the base download directory "{real_base_directory}"'}
if not os.path.isdir(dldirectory):
- if self.config.CREATE_CUSTOM_DIRS != 'true':
+ if not self.config.CREATE_CUSTOM_DIRS:
return {'status': 'error', 'msg': f'Folder "{folder}" for download does not exist inside base directory "{real_base_directory}", and CREATE_CUSTOM_DIRS is not true in the configuration.'}
os.makedirs(dldirectory, exist_ok=True)
else:
bgstack15