|
@@ -1,21 +1,51 @@
|
|
|
import os
|
|
import os
|
|
|
import helper.console as console
|
|
import helper.console as console
|
|
|
|
|
|
|
|
|
|
+class SettingEntry:
|
|
|
|
|
+ def __init__(self, name, env_name=None, default=None, namespace=None, type=str):
|
|
|
|
|
+ self.name = name
|
|
|
|
|
+ self.environment = env_name
|
|
|
|
|
+ self.default = default
|
|
|
|
|
+ self.value = default
|
|
|
|
|
+ self.namespace = namespace
|
|
|
|
|
+ self.read_from_env = False
|
|
|
|
|
+ self.type = type
|
|
|
|
|
+
|
|
|
|
|
+ if os.getenv(self.environment) is not None:
|
|
|
|
|
+ self.read_from_env = True
|
|
|
|
|
+ self.set(os.getenv(self.environment))
|
|
|
|
|
+
|
|
|
|
|
+ def __str__(self):
|
|
|
|
|
+ return '{} => {}'.format(self.name, self.value)
|
|
|
|
|
+
|
|
|
|
|
+ def __eq__(self, other):
|
|
|
|
|
+ return self.name == other
|
|
|
|
|
+
|
|
|
|
|
+ def read_config(self, config):
|
|
|
|
|
+ if self.namespace in config and self.name in config[self.namespace] and not self.read_from_env:
|
|
|
|
|
+ self.set(config[self.namespace][self.name])
|
|
|
|
|
+
|
|
|
|
|
+ def set(self, value):
|
|
|
|
|
+ self.value = self.type(value)
|
|
|
|
|
+
|
|
|
|
|
+ def get(self):
|
|
|
|
|
+ return self.type(self.value)
|
|
|
|
|
+
|
|
|
class Settings:
|
|
class Settings:
|
|
|
# Directory to permanently save the file (ENV: MD_SAVEDIR)
|
|
# Directory to permanently save the file (ENV: MD_SAVEDIR)
|
|
|
- SaveDir = None
|
|
|
|
|
|
|
+ SaveDir = SettingEntry('saveDir', 'MD_SAVEDIR', '~/Downloads', 'music-downloader', os.path.expanduser)
|
|
|
|
|
|
|
|
# Directory to temporary download the file (ENV: MD_TMP)
|
|
# Directory to temporary download the file (ENV: MD_TMP)
|
|
|
- tmpDir = '/tmp'
|
|
|
|
|
|
|
+ tmpDir = SettingEntry('tmpDir', 'MD_TMP', '~/tmp', 'music-downloader', os.path.expanduser)
|
|
|
|
|
|
|
|
# Minimal debug level (ENV: MD_LOGGING)
|
|
# Minimal debug level (ENV: MD_LOGGING)
|
|
|
- Debuglvl = 0
|
|
|
|
|
|
|
+ Debuglvl = SettingEntry('debuglvl', 'MD_LOGGING', 0, 'music-downloader', int)
|
|
|
|
|
|
|
|
# Minimal bitrate to auto download the file (ENV: MD_QUALITY)
|
|
# Minimal bitrate to auto download the file (ENV: MD_QUALITY)
|
|
|
- MinQuality = 300
|
|
|
|
|
|
|
+ MinQuality = SettingEntry('minQuality', 'MD_QUALITY', 300, 'music-downloader', int)
|
|
|
|
|
|
|
|
#Format for downloaded file ID3 comment
|
|
#Format for downloaded file ID3 comment
|
|
|
- CommentFormat = None
|
|
|
|
|
|
|
+ CommentFormat = SettingEntry('saveDir', 'MD_SAVEDIR', '~/Downloads', 'music-downloader')
|
|
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
|
def import_config(config):
|
|
def import_config(config):
|
|
@@ -33,17 +63,14 @@ class Settings:
|
|
|
Settings.CommentFormat = config[namespace]['commentFormat']
|
|
Settings.CommentFormat = config[namespace]['commentFormat']
|
|
|
|
|
|
|
|
if os.getenv('MD_SAVEDIR') is not None:
|
|
if os.getenv('MD_SAVEDIR') is not None:
|
|
|
- console.output('Overrule MD_SAVEDIR', console.DBG_INFO)
|
|
|
|
|
Settings.SaveDir = os.getenv('MD_SAVEDIR')
|
|
Settings.SaveDir = os.getenv('MD_SAVEDIR')
|
|
|
if os.getenv('MD_TMP') is not None:
|
|
if os.getenv('MD_TMP') is not None:
|
|
|
- console.output('Overrule MD_TMP', console.DBG_INFO)
|
|
|
|
|
Settings.SaveDir = os.getenv('MD_TMP')
|
|
Settings.SaveDir = os.getenv('MD_TMP')
|
|
|
if os.getenv('MD_LOGGING') is not None:
|
|
if os.getenv('MD_LOGGING') is not None:
|
|
|
- console.output('Overrule MD_LOGGING', console.DBG_INFO)
|
|
|
|
|
Settings.SaveDir = os.getenv('MD_LOGGING')
|
|
Settings.SaveDir = os.getenv('MD_LOGGING')
|
|
|
if os.getenv('MD_QUALITY') is not None:
|
|
if os.getenv('MD_QUALITY') is not None:
|
|
|
- console.output('Overrule MD_QUALITY', console.DBG_INFO)
|
|
|
|
|
Settings.SaveDir = os.getenv('MD_QUALITY')
|
|
Settings.SaveDir = os.getenv('MD_QUALITY')
|
|
|
|
|
|
|
|
Settings.SaveDir = os.path.expanduser(Settings.SaveDir)
|
|
Settings.SaveDir = os.path.expanduser(Settings.SaveDir)
|
|
|
Settings.tmpDir = os.path.expanduser(Settings.tmpDir)
|
|
Settings.tmpDir = os.path.expanduser(Settings.tmpDir)
|
|
|
|
|
+ Settings.Debuglvl = int(Settings.Debuglvl)
|