| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import configparser
- import os
- from pathlib import Path
- from helper import console
- class Settings:
- # Collect all the setting instances
- __list__ = []
- __config__ = None
- __file__ = Path('settings.ini')
- def initialize():
- from .settingsentry import SettingEntry
- # Directory to permanently save the file (ENV: MD_SAVEDIR)
- Settings.SaveDir = SettingEntry('saveDir', 'MD_SAVEDIR', '~/Downloads', 'music-downloader', os.path.expanduser)
- # Directory to temporary download the file (ENV: MD_TMP)
- Settings.tmpDir = SettingEntry('tmpDir', 'MD_TMP', '~/tmp', 'music-downloader', os.path.expanduser)
- # Minimal debug level (ENV: MD_LOGGING)
- Settings.Debuglvl = SettingEntry('debuglvl', 'MD_LOGGING', 0, 'music-downloader', int)
- # Minimal bitrate to auto download the file (ENV: MD_QUALITY)
- Settings.MinQuality = SettingEntry('minQuality', 'MD_QUALITY', 300, 'music-downloader', int)
- # Format for downloaded file ID3 comment
- Settings.CommentFormat = SettingEntry('commentFormat', 'MD_COMMENT', '', 'music-downloader')
- # Spotify settings
- Settings.SpotifyUsername = SettingEntry(namespace='spotify', name='username')
- Settings.SpotifyClientID = SettingEntry(namespace='spotify', name='clientid')
- Settings.SpotifySecret = SettingEntry(namespace='spotify', name='secret')
- Settings.SpotifyScope = SettingEntry(namespace='spotify', name='scope', default='playlist-read-private,playlist-read-collaborative')
- def write():
- for entry in Settings.__list__:
- entry.push_config()
- console.output('Writing settings to \'{0}\''.format(Settings.__file__.absolute()), console.DBG_INFO)
- Settings.__config__.write(Settings.__file__.open('w'))
- def read():
- _config = configparser.RawConfigParser()
- if Settings.__file__.exists():
- console.output('Reading settings from \'{0}\''.format(Settings.__file__.absolute()), console.DBG_INFO)
- _config.read(Settings.__file__)
- Settings.__config__ = _config
- else:
- console.output('Settings not found at \'{0}\''.format(Settings.__file__.absolute()), console.DBG_INFO)
- SaveDir = None
- tmpDir = None
- Debuglvl = None
- MinQuality = None
- CommentFormat = None
- SpotifyUsername = None
- SpotifyClientID = None
- SpotifySecret = None
- SpotifyScope = None
|