Browse Source

global setup

Deben Oldert 6 years ago
parent
commit
b3882ee391
3 changed files with 55 additions and 3 deletions
  1. 38 1
      helper/settings.py
  2. 11 2
      main.py
  3. 6 0
      settings.ini

+ 38 - 1
helper/settings.py

@@ -1,3 +1,6 @@
+import os
+import helper.console as console
+
 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 = None
@@ -6,7 +9,41 @@ class Settings:
     tmpDir = '/tmp'
     tmpDir = '/tmp'
 
 
     # Minimal debug level (ENV: MD_LOGGING)
     # Minimal debug level (ENV: MD_LOGGING)
-    Debuglvl = None
+    Debuglvl = 0
 
 
     # Minimal bitrate to auto download the file (ENV: MD_QUALITY)
     # Minimal bitrate to auto download the file (ENV: MD_QUALITY)
     MinQuality = 300
     MinQuality = 300
+
+    #Format for downloaded file ID3 comment
+    CommentFormat = None
+
+    @staticmethod
+    def import_config(config):
+        namespace = 'music-downloader'
+        if namespace in config:
+            if 'saveDir' in config[namespace]:
+                Settings.SaveDir = config[namespace]['saveDir']
+            if 'tmpDir' in config[namespace]:
+                Settings.tmpDir = config[namespace]['tmpDir']
+            if 'debuglvl' in config[namespace]:
+                Settings.Debuglvl = config[namespace]['debuglvl']
+            if 'minQuality' in config[namespace]:
+                Settings.MinQuality = config[namespace]['minQuality']
+            if 'commentFormat' in config[namespace]:
+                Settings.CommentFormat = config[namespace]['commentFormat']
+
+        if os.getenv('MD_SAVEDIR') is not None:
+            console.output('Overrule MD_SAVEDIR', console.DBG_INFO)
+            Settings.SaveDir = os.getenv('MD_SAVEDIR')
+        if os.getenv('MD_TMP') is not None:
+            console.output('Overrule MD_TMP', console.DBG_INFO)
+            Settings.SaveDir = os.getenv('MD_TMP')
+        if os.getenv('MD_LOGGING') is not None:
+            console.output('Overrule MD_LOGGING', console.DBG_INFO)
+            Settings.SaveDir = os.getenv('MD_LOGGING')
+        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.path.expanduser(Settings.SaveDir)
+        Settings.tmpDir = os.path.expanduser(Settings.tmpDir)

+ 11 - 2
main.py

@@ -1,10 +1,18 @@
 import sites as sites
 import sites as sites
 from helper import console as console
 from helper import console as console
 import os.path
 import os.path
+import configparser
 from helper.settings import Settings
 from helper.settings import Settings
 
 
 
 
 def init():
 def init():
+    if os.path.isfile('settings.ini'):
+        console.output('Settings file found', console.DBG_INFO)
+        config = configparser.ConfigParser()
+        config.read('settings.ini')
+        Settings.import_config(config)
+        console.output('Settings loaded', console.DBG_INFO)
+
     dbg_lvl = os.getenv('MD_LOGGING', 'ERROR')
     dbg_lvl = os.getenv('MD_LOGGING', 'ERROR')
 
 
     if dbg_lvl.lower() == 'info':
     if dbg_lvl.lower() == 'info':
@@ -22,10 +30,11 @@ def init():
 
 
 
 
 def main():
 def main():
-    init()
-
     console.output('Music downloader by Deben Oldert')
     console.output('Music downloader by Deben Oldert')
     console.output()
     console.output()
+
+    init()
+
     console.output('Download directory: {0}'.format(Settings.SaveDir))
     console.output('Download directory: {0}'.format(Settings.SaveDir))
     console.output()
     console.output()
     help()
     help()

+ 6 - 0
settings.ini

@@ -0,0 +1,6 @@
+[music-downloader]
+saveDir=~/Downloads
+tmpDir=/tmp
+debuglvl=0
+minQuality=300
+commentFormat=LABEL:{label};