From bcdb07593a7e7fe43540fdf9840a70773d0bc9e2 Mon Sep 17 00:00:00 2001 From: el-gringo-alto <22480930+el-gringo-alto@users.noreply.github.com> Date: Sun, 24 Oct 2021 22:14:22 -0400 Subject: [PATCH 1/2] Generate config file if it doesn't exist --- zspotify/const.py | 12 ++++++++++++ zspotify/zspotify.py | 12 +++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/zspotify/const.py b/zspotify/const.py index f44d869..3e4d9b0 100644 --- a/zspotify/const.py +++ b/zspotify/const.py @@ -95,3 +95,15 @@ OVERRIDE_AUTO_WAIT = 'OVERRIDE_AUTO_WAIT' CHUNK_SIZE = 'CHUNK_SIZE' SPLIT_ALBUM_DISCS = 'SPLIT_ALBUM_DISCS' + +CONFIG_DEFAULT_SETTINGS = { + 'ROOT_PATH': '../ZSpotify Music/', + 'ROOT_PODCAST_PATH': '../ZSpotify Podcasts/', + 'SKIP_EXISTING_FILES': True, + 'DOWNLOAD_FORMAT': 'mp3', + 'FORCE_PREMIUM': False, + 'ANTI_BAN_WAIT_TIME': 1, + 'OVERRIDE_AUTO_WAIT': False, + 'CHUNK_SIZE': 50000, + 'SPLIT_ALBUM_DISCS': False +} diff --git a/zspotify/zspotify.py b/zspotify/zspotify.py index f206a80..5739dfa 100644 --- a/zspotify/zspotify.py +++ b/zspotify/zspotify.py @@ -18,7 +18,7 @@ from librespot.core import Session from const import CREDENTIALS_JSON, TYPE, \ PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, CONFIG_FILE_PATH, FORCE_PREMIUM, \ - PLAYLIST_READ_PRIVATE + PLAYLIST_READ_PRIVATE, CONFIG_DEFAULT_SETTINGS from utils import MusicFormat @@ -55,8 +55,14 @@ class ZSpotify: @classmethod def load_config(cls) -> None: app_dir = os.path.dirname(__file__) - with open(os.path.join(app_dir, CONFIG_FILE_PATH), encoding='utf-8') as config_file: - cls.CONFIG = json.load(config_file) + true_config_file_path = os.path.join(app_dir, CONFIG_FILE_PATH) + if not os.path.exists(true_config_file_path): + with open(true_config_file_path, 'w', encoding='utf-8') as config_file: + json.dump(CONFIG_DEFAULT_SETTINGS, config_file, indent=4) + cls.CONFIG = CONFIG_DEFAULT_SETTINGS + else: + with open(true_config_file_path, encoding='utf-8') as config_file: + cls.CONFIG = json.load(config_file) @classmethod def get_config(cls, key) -> Any: From 23c53247f7bf28df85b11ff9d9d4c33eb8ac376a Mon Sep 17 00:00:00 2001 From: el-gringo-alto <22480930+el-gringo-alto@users.noreply.github.com> Date: Sun, 24 Oct 2021 22:24:05 -0400 Subject: [PATCH 2/2] Config file is removed from the repository --- .gitignore | 3 +++ zs_config.json | 11 ----------- 2 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 zs_config.json diff --git a/.gitignore b/.gitignore index ea24040..65696ce 100644 --- a/.gitignore +++ b/.gitignore @@ -151,3 +151,6 @@ ZSpotify\ Podcasts/ # Intellij .idea + +# Config file +zs_config.json diff --git a/zs_config.json b/zs_config.json deleted file mode 100644 index b5dbb91..0000000 --- a/zs_config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ROOT_PATH": "../ZSpotify Music/", - "ROOT_PODCAST_PATH": "../ZSpotify Podcasts/", - "SKIP_EXISTING_FILES": true, - "DOWNLOAD_FORMAT": "mp3", - "FORCE_PREMIUM": false, - "ANTI_BAN_WAIT_TIME": 1, - "OVERRIDE_AUTO_WAIT": false, - "CHUNK_SIZE": 50000, - "SPLIT_ALBUM_DISCS": false -} \ No newline at end of file