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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
--- 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' },
@@ -49,7 +49,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' },
+ CREDENTIALS_LOCATION: { 'default': '~/.local/share/zspotify/credentials.json', 'type': str, 'arg': '--credentials-location' },
OUTPUT: { 'default': '', 'type': str, 'arg': '--output' },
PRINT_SPLASH: { 'default': 'False', 'type': bool, 'arg': '--print-splash' },
PRINT_SKIPS: { 'default': 'True', 'type': bool, 'arg': '--print-skips' },
@@ -82,21 +82,21 @@ 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()
- else:
- with open(true_config_file_path, encoding='utf-8') as config_file:
- jsonvalues = json.load(config_file)
- cls.Values = {}
- for key in CONFIG_VALUES:
- if key in jsonvalues:
- cls.Values[key] = cls.parse_arg_value(key, jsonvalues[key])
+
+ with open(true_config_file_path, encoding='utf-8') as config_file:
+ jsonvalues = json.load(config_file)
+ cls.Values = {}
+ for key in CONFIG_VALUES:
+ if key in jsonvalues:
+ cls.Values[key] = cls.parse_arg_value(key, jsonvalues[key])
# Add default values for missing keys
@@ -142,11 +142,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 +194,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/track.py
+++ b/zspotify/track.py
@@ -199,7 +199,7 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba
unit_divisor=1024,
disable=disable_progressbar
) as p_bar:
- for _ in range(int(total_size / ZSpotify.CONFIG.get_chunk_size()) + 1):
+ while stream.input_stream.stream().available() != 0:
data = stream.input_stream.stream().read(ZSpotify.CONFIG.get_chunk_size())
p_bar.update(file.write(data))
downloaded += len(data)
--- 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
|