settings.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os
  2. import helper.console as console
  3. class Settings:
  4. # Directory to permanently save the file (ENV: MD_SAVEDIR)
  5. SaveDir = None
  6. # Directory to temporary download the file (ENV: MD_TMP)
  7. tmpDir = '/tmp'
  8. # Minimal debug level (ENV: MD_LOGGING)
  9. Debuglvl = 0
  10. # Minimal bitrate to auto download the file (ENV: MD_QUALITY)
  11. MinQuality = 300
  12. #Format for downloaded file ID3 comment
  13. CommentFormat = None
  14. @staticmethod
  15. def import_config(config):
  16. namespace = 'music-downloader'
  17. if namespace in config:
  18. if 'saveDir' in config[namespace]:
  19. Settings.SaveDir = config[namespace]['saveDir']
  20. if 'tmpDir' in config[namespace]:
  21. Settings.tmpDir = config[namespace]['tmpDir']
  22. if 'debuglvl' in config[namespace]:
  23. Settings.Debuglvl = config[namespace]['debuglvl']
  24. if 'minQuality' in config[namespace]:
  25. Settings.MinQuality = config[namespace]['minQuality']
  26. if 'commentFormat' in config[namespace]:
  27. Settings.CommentFormat = config[namespace]['commentFormat']
  28. if os.getenv('MD_SAVEDIR') is not None:
  29. console.output('Overrule MD_SAVEDIR', console.DBG_INFO)
  30. Settings.SaveDir = os.getenv('MD_SAVEDIR')
  31. if os.getenv('MD_TMP') is not None:
  32. console.output('Overrule MD_TMP', console.DBG_INFO)
  33. Settings.SaveDir = os.getenv('MD_TMP')
  34. if os.getenv('MD_LOGGING') is not None:
  35. console.output('Overrule MD_LOGGING', console.DBG_INFO)
  36. Settings.SaveDir = os.getenv('MD_LOGGING')
  37. if os.getenv('MD_QUALITY') is not None:
  38. console.output('Overrule MD_QUALITY', console.DBG_INFO)
  39. Settings.SaveDir = os.getenv('MD_QUALITY')
  40. Settings.SaveDir = os.path.expanduser(Settings.SaveDir)
  41. Settings.tmpDir = os.path.expanduser(Settings.tmpDir)