|
@@ -1,12 +1,57 @@
|
|
|
|
|
+import os
|
|
|
|
|
+import configparser
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+CONFIG = configparser.ConfigParser()
|
|
|
|
|
+if os.path.isfile('settings.ini'):
|
|
|
|
|
+ CONFIG.read('settings.ini')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class SettingEntry:
|
|
|
|
|
+ def __init__(self, name, env_name=None, default=None, namespace='DEFAULT', 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
|
|
|
|
|
+
|
|
|
|
|
+ self.read_config()
|
|
|
|
|
+
|
|
|
|
|
+ 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):
|
|
|
|
|
+ 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 = None
|
|
|
|
|
|
|
+ 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
|
|
|
|
|
+ CommentFormat = SettingEntry('saveDir', 'MD_SAVEDIR', '~/Downloads', 'music-downloader')
|