diff --git a/zspotify/config.py b/zspotify/config.py index a432000..ca10910 100644 --- a/zspotify/config.py +++ b/zspotify/config.py @@ -19,6 +19,7 @@ DOWNLOAD_REAL_TIME = 'DOWNLOAD_REAL_TIME' LANGUAGE = 'LANGUAGE' BITRATE = 'BITRATE' SONG_ARCHIVE = 'SONG_ARCHIVE' +CREDENTIALS_LOCATION = 'CREDENTIALS_LOCATION' CONFIG_VALUES = { ROOT_PATH: { 'default': '../ZSpotify Music/', 'type': str, 'arg': '--root-path' }, @@ -35,6 +36,7 @@ CONFIG_VALUES = { LANGUAGE: { 'default': 'en', 'type': str, 'arg': '--language' }, BITRATE: { 'default': '', 'type': str, 'arg': '--bitrate' }, SONG_ARCHIVE: { 'default': '.song_archive', 'type': str, 'arg': '--song-archive' }, + CREDENTIALS_LOCATION: { 'default': 'credentials.json', 'type': str, 'arg': '--credentials-location' }, } @@ -77,8 +79,6 @@ class Config: if key.lower() in vars(args) and vars(args)[key.lower()] is not None: cls.Values[key] = cls.parse_arg_value(key, vars(args)[key.lower()]) - print(cls.Values, ' ', '\n') - @classmethod def get_default_json(cls) -> Any: r = {} @@ -161,3 +161,7 @@ class Config: @classmethod def get_song_archive(cls) -> str: return cls.get(SONG_ARCHIVE) + + @classmethod + def get_credentials_location(cls) -> str: + return cls.get(CREDENTIALS_LOCATION) diff --git a/zspotify/const.py b/zspotify/const.py index 828bdd3..057921c 100644 --- a/zspotify/const.py +++ b/zspotify/const.py @@ -80,8 +80,6 @@ USER_LIBRARY_READ = 'user-library-read' WINDOWS_SYSTEM = 'Windows' -CREDENTIALS_JSON = 'credentials.json' - CODEC_MAP = { 'aac': 'aac', 'fdk_aac': 'libfdk_aac', diff --git a/zspotify/zspotify.py b/zspotify/zspotify.py index 1fe7a64..51ef6c6 100644 --- a/zspotify/zspotify.py +++ b/zspotify/zspotify.py @@ -16,10 +16,9 @@ import requests from librespot.audio.decoders import VorbisOnlyAudioQuality from librespot.core import Session -from const import CREDENTIALS_JSON, TYPE, \ +from const import TYPE, \ PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, \ PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ -from utils import MusicFormat from config import Config @@ -36,9 +35,11 @@ class ZSpotify: def login(cls): """ Authenticates with Spotify and saves credentials to a file """ - if os.path.isfile(CREDENTIALS_JSON): + cred_location = os.path.join(os.getcwd(), Config.get_credentials_location()) + + if os.path.isfile(cred_location): try: - cls.SESSION = Session.Builder().stored_file().create() + cls.SESSION = Session.Builder().stored_file(cred_location).create() return except RuntimeError: pass