mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-12-02 04:23:57 +01:00
Added CREDENTIALS_LOCATION config value
This commit is contained in:
parent
0adaa20d59
commit
ad43153d4c
@ -19,6 +19,7 @@ DOWNLOAD_REAL_TIME = 'DOWNLOAD_REAL_TIME'
|
|||||||
LANGUAGE = 'LANGUAGE'
|
LANGUAGE = 'LANGUAGE'
|
||||||
BITRATE = 'BITRATE'
|
BITRATE = 'BITRATE'
|
||||||
SONG_ARCHIVE = 'SONG_ARCHIVE'
|
SONG_ARCHIVE = 'SONG_ARCHIVE'
|
||||||
|
CREDENTIALS_LOCATION = 'CREDENTIALS_LOCATION'
|
||||||
|
|
||||||
CONFIG_VALUES = {
|
CONFIG_VALUES = {
|
||||||
ROOT_PATH: { 'default': '../ZSpotify Music/', 'type': str, 'arg': '--root-path' },
|
ROOT_PATH: { 'default': '../ZSpotify Music/', 'type': str, 'arg': '--root-path' },
|
||||||
@ -35,6 +36,7 @@ CONFIG_VALUES = {
|
|||||||
LANGUAGE: { 'default': 'en', 'type': str, 'arg': '--language' },
|
LANGUAGE: { 'default': 'en', 'type': str, 'arg': '--language' },
|
||||||
BITRATE: { 'default': '', 'type': str, 'arg': '--bitrate' },
|
BITRATE: { 'default': '', 'type': str, 'arg': '--bitrate' },
|
||||||
SONG_ARCHIVE: { 'default': '.song_archive', 'type': str, 'arg': '--song-archive' },
|
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:
|
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()])
|
cls.Values[key] = cls.parse_arg_value(key, vars(args)[key.lower()])
|
||||||
|
|
||||||
print(cls.Values, ' ', '\n')
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_default_json(cls) -> Any:
|
def get_default_json(cls) -> Any:
|
||||||
r = {}
|
r = {}
|
||||||
@ -161,3 +161,7 @@ class Config:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_song_archive(cls) -> str:
|
def get_song_archive(cls) -> str:
|
||||||
return cls.get(SONG_ARCHIVE)
|
return cls.get(SONG_ARCHIVE)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_credentials_location(cls) -> str:
|
||||||
|
return cls.get(CREDENTIALS_LOCATION)
|
||||||
|
@ -80,8 +80,6 @@ USER_LIBRARY_READ = 'user-library-read'
|
|||||||
|
|
||||||
WINDOWS_SYSTEM = 'Windows'
|
WINDOWS_SYSTEM = 'Windows'
|
||||||
|
|
||||||
CREDENTIALS_JSON = 'credentials.json'
|
|
||||||
|
|
||||||
CODEC_MAP = {
|
CODEC_MAP = {
|
||||||
'aac': 'aac',
|
'aac': 'aac',
|
||||||
'fdk_aac': 'libfdk_aac',
|
'fdk_aac': 'libfdk_aac',
|
||||||
|
@ -16,10 +16,9 @@ import requests
|
|||||||
from librespot.audio.decoders import VorbisOnlyAudioQuality
|
from librespot.audio.decoders import VorbisOnlyAudioQuality
|
||||||
from librespot.core import Session
|
from librespot.core import Session
|
||||||
|
|
||||||
from const import CREDENTIALS_JSON, TYPE, \
|
from const import TYPE, \
|
||||||
PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, \
|
PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, \
|
||||||
PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ
|
PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ
|
||||||
from utils import MusicFormat
|
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
@ -36,9 +35,11 @@ class ZSpotify:
|
|||||||
def login(cls):
|
def login(cls):
|
||||||
""" Authenticates with Spotify and saves credentials to a file """
|
""" 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:
|
try:
|
||||||
cls.SESSION = Session.Builder().stored_file().create()
|
cls.SESSION = Session.Builder().stored_file(cred_location).create()
|
||||||
return
|
return
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user