1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
--- a/zspotify/config.py
+++ b/zspotify/config.py
@@ -2,7 +2,7 @@ import json
import os
from typing import Any
-CONFIG_FILE_PATH = '../zs_config.json'
+CONFIG_FILE_PATH = '~/.local/share/zspotify/zs_config.json'
ROOT_PATH = 'ROOT_PATH'
ROOT_PODCAST_PATH = 'ROOT_PODCAST_PATH'
@@ -34,8 +34,8 @@ PRINT_WARNINGS = 'PRINT_WARNINGS'
RETRY_ATTEMPTS = 'RETRY_ATTEMPTS'
CONFIG_VALUES = {
- ROOT_PATH: { 'default': '../ZSpotify Music/', 'type': str, 'arg': '--root-path' },
- ROOT_PODCAST_PATH: { 'default': '../ZSpotify Podcasts/', 'type': str, 'arg': '--root-podcast-path' },
+ ROOT_PATH: { 'default': './', 'type': str, 'arg': '--root-path' },
+ ROOT_PODCAST_PATH: { 'default': './', 'type': str, 'arg': '--root-podcast-path' },
SKIP_EXISTING_FILES: { 'default': 'True', 'type': bool, 'arg': '--skip-existing-files' },
SKIP_PREVIOUSLY_DOWNLOADED: { 'default': 'False', 'type': bool, 'arg': '--skip-previously-downloaded' },
RETRY_ATTEMPTS: { 'default': '5', 'type': int, 'arg': '--retry-attemps' },
@@ -43,14 +43,14 @@ CONFIG_VALUES = {
FORCE_PREMIUM: { 'default': 'False', 'type': bool, 'arg': '--force-premium' },
ANTI_BAN_WAIT_TIME: { 'default': '1', 'type': int, 'arg': '--anti-ban-wait-time' },
OVERRIDE_AUTO_WAIT: { 'default': 'False', 'type': bool, 'arg': '--override-auto-wait' },
- CHUNK_SIZE: { 'default': '50000', 'type': int, 'arg': '--chunk-size' },
+ CHUNK_SIZE: { 'default': 50000, 'type': int, 'arg': '--chunk-size' },
SPLIT_ALBUM_DISCS: { 'default': 'False', 'type': bool, 'arg': '--split-album-discs' },
DOWNLOAD_REAL_TIME: { 'default': 'False', 'type': bool, 'arg': '--download-real-time' },
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' },
- OUTPUT: { 'default': '', 'type': str, 'arg': '--output' },
+ CREDENTIALS_LOCATION: { 'default': '~/.local/share/zspotify/credentials.json', 'type': str, 'arg': '--credentials-location' },
+ OUTPUT: { 'default': '{artist} - {song_name}.ogg','type': str, 'arg': '--output' },
PRINT_SPLASH: { 'default': 'False', 'type': bool, 'arg': '--print-splash' },
PRINT_SKIPS: { 'default': 'True', 'type': bool, 'arg': '--print-skips' },
PRINT_DOWNLOAD_PROGRESS: { 'default': 'True', 'type': bool, 'arg': '--print-download-progress' },
@@ -82,11 +82,12 @@ class Config:
if args.config_location:
config_fp = args.config_location
- true_config_file_path = os.path.join(app_dir, config_fp)
+ true_config_file_path = os.path.expanduser(config_fp)
# Load config from zs_config.json
if not os.path.exists(true_config_file_path):
+ os.makedirs(os.path.dirname(true_config_file_path), exist_ok=True)
with open(true_config_file_path, 'w', encoding='utf-8') as config_file:
json.dump(cls.get_default_json(), config_file, indent=4)
cls.Values = cls.get_default_json()
@@ -142,11 +143,11 @@ class Config:
@classmethod
def get_root_path(cls) -> str:
- return os.path.join(os.path.dirname(__file__), cls.get(ROOT_PATH))
+ return os.path.expanduser(cls.get(ROOT_PATH))
@classmethod
def get_root_podcast_path(cls) -> str:
- return os.path.join(os.path.dirname(__file__), cls.get(ROOT_PODCAST_PATH))
+ return os.path.expanduser(cls.get(ROOT_PODCAST_PATH))
@classmethod
def get_skip_existing_files(cls) -> bool:
@@ -194,17 +195,17 @@ class Config:
@classmethod
def get_song_archive(cls) -> str:
- return os.path.join(cls.get_root_path(), cls.get(SONG_ARCHIVE))
+ return os.path.expanduser(cls.get(SONG_ARCHIVE))
@classmethod
def get_credentials_location(cls) -> str:
- return os.path.join(os.getcwd(), cls.get(CREDENTIALS_LOCATION))
+ return os.path.expanduser(cls.get(CREDENTIALS_LOCATION))
@classmethod
def get_temp_download_dir(cls) -> str:
if cls.get(TEMP_DOWNLOAD_DIR) == '':
return ''
- return os.path.join(cls.get_root_path(), cls.get(TEMP_DOWNLOAD_DIR))
+ return os.path.expanduser(cls.get(TEMP_DOWNLOAD_DIR))
@classmethod
def get_all_genres(cls) -> bool:
--- a/zspotify/zspotify.py
+++ b/zspotify/zspotify.py
@@ -28,7 +28,9 @@ class ZSpotify:
if os.path.isfile(cred_location):
try:
- cls.SESSION = Session.Builder().stored_file(cred_location).create()
+ Session.Configuration.stored_credentials_file = cred_location
+ Session.Configuration.Builder.stored_credentials_file = cred_location
+ cls.SESSION = Session.Builder().stored_file().create()
return
except RuntimeError:
pass
|