Skip to content

Commit 43affae

Browse files
committed
Fix logging and crashes for new users
Fix logging and crashes for new users. Add .spec file and build.sh to generate binaries !
1 parent 065b994 commit 43affae

File tree

7 files changed

+96
-77
lines changed

7 files changed

+96
-77
lines changed

build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
rm -rf ./dist
3+
rm -rf ./build
4+
python3 -m venv venv
5+
source ./venv/bin/activate
6+
pip install pyinstaller
7+
pip install -r requirements.txt
8+
pyinstaller build.spec
9+
chmod +x ./dist/onthespot

config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def __init__(self, cfg_path=None):
3434
with open(self.__cfg_path, "w") as cf:
3535
cf.write(json.dumps(self.__template_data))
3636
self.__config = self.__template_data
37-
os.makedirs(os.path.dirname(self.get("dlid_cache")), exist_ok=True)
3837
os.makedirs(self.get("download_root"), exist_ok=True)
3938
os.makedirs(os.path.dirname(self.get("log_file")), exist_ok=True)
4039

onthespot.py

Lines changed: 38 additions & 42 deletions
Large diffs are not rendered by default.

requirements.txt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
pyqt5
2-
librespot
3-
requests
4-
pydub
5-
music_tag
1+
async-timeout==4.0.2
2+
certifi==2022.9.24
3+
charset-normalizer==2.1.1
4+
defusedxml==0.7.1
5+
idna==3.4
6+
ifaddr==0.2.0
7+
librespot==0.0.6
8+
music-tag==0.4.3
9+
mutagen==1.45.1
10+
protobuf==3.20.1
11+
pycryptodomex==3.15.0
12+
pydub==0.25.1
13+
PyOgg==0.6.14a1
14+
PyQt5==5.15.7
15+
PyQt5-Qt5==5.15.2
16+
PyQt5-sip==12.11.0
17+
requests==2.28.1
18+
urllib3==1.26.12
19+
websocket-client==1.4.0
20+
zeroconf==0.39.0

runtimedata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from config import config
44
import logging
5-
import sys
5+
import sys, os
66
import logging
77
from logging.handlers import RotatingFileHandler
88

@@ -15,12 +15,12 @@
1515
download_queue = Queue()
1616
thread_pool = []
1717
session_pool = []
18-
18+
loglevel = int(os.environ.get("LOGLEVEL", 20))
1919
def get_logger(name):
2020
logger = logging.getLogger(name)
2121
logger.addHandler(log_handler)
2222
logger.addHandler(stdout_handler)
23-
logger.setLevel(logging.DEBUG)
23+
logger.setLevel(loglevel)
2424
return logger
2525

2626
def handle_exception(exc_type, exc_value, exc_traceback):

spotutils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def search_by_term(session, search_term, max_results=20)->dict:
148148
"artists": resp.json()["artists"]["items"],
149149
}
150150
if len(results["tracks"]) + len(results["albums"]) + len(results["artists"]) + len(results["playlists"]) == 0:
151-
logger.debug(f"No results for term '{search_term}', max items '{max_results}'")
151+
logger.warning(f"No results for term '{search_term}', max items '{max_results}'")
152152
raise EmptySearchResultException("No result found for search term '{}' ".format(search_term))
153153
else:
154154
return results
@@ -254,7 +254,7 @@ def download_track(self, session, track_id_str, extra_paths="", prefix=False, pr
254254
else:
255255
if os.path.isfile(filename) and os.path.getsize(filename) and SKIP_EXISTING_FILES:
256256
self.progress.emit([track_id_str, "Already exists", [100, 100]])
257-
logger.debug(f"File already exists, Skipping download for track by id '{track_id_str}'")
257+
logger.info(f"File already exists, Skipping download for track by id '{track_id_str}'")
258258
return False
259259
else:
260260
if track_id_str != scraped_song_id:
@@ -271,7 +271,7 @@ def download_track(self, session, track_id_str, extra_paths="", prefix=False, pr
271271
with open(filename, 'wb') as file:
272272
while downloaded < total_size:
273273
data = stream.input_stream.stream().read(_CHUNK_SIZE)
274-
logger.info(f"Reading chunk of {_CHUNK_SIZE} bytes for track by id '{track_id_str}'")
274+
logger.debug(f"Reading chunk of {_CHUNK_SIZE} bytes for track by id '{track_id_str}'")
275275
downloaded += len(data)
276276
if len(data) != 0:
277277
file.write(data)
@@ -292,7 +292,7 @@ def download_track(self, session, track_id_str, extra_paths="", prefix=False, pr
292292
return None
293293
self.progress.emit([track_id_str, None, [downloaded, total_size]])
294294
if not config.get("force_raw"):
295-
logger.debug(f"Force raw is disabled for track by id '{track_id_str}', media converting and tagging will be done !")
295+
logger.warning(f"Force raw is disabled for track by id '{track_id_str}', media converting and tagging will be done !")
296296
self.progress.emit([track_id_str, "Converting", None])
297297
convert_audio_format(filename, quality)
298298
self.progress.emit([track_id_str, "Writing metadata", None])
@@ -328,7 +328,7 @@ def download_track(self, session, track_id_str, extra_paths="", prefix=False, pr
328328
return False
329329

330330
def download_episode(self, episode_id_str, extra_paths=""):
331-
logger.debug(f"Downloading episode by id '{episode_id_str}'")
331+
logger.info(f"Downloading episode by id '{episode_id_str}'")
332332
ROOT_PODCAST_PATH = os.path.join(config.get("download_root"), "Podcasts")
333333
quality = AudioQuality.HIGH
334334
podcast_name, episode_name = get_episode_info(episode_id_str)
@@ -369,22 +369,22 @@ def download_episode(self, episode_id_str, extra_paths=""):
369369
self.progress.emit([episode_id_str, "Downloaded", [100, 100]])
370370
return True
371371
else:
372-
logger.debug(f"Downloading failed for episode by id '{episode_id_str}', partial download failed !")
372+
logger.error(f"Downloading failed for episode by id '{episode_id_str}', partial download failed !")
373373
self.progress.emit([episode_id_str, "Failed", [0, 100]])
374374
return False
375375
except:
376-
logger.debug(f"Downloading failed for episode by id '{episode_id_str}', Unexpected Exception: {traceback.format_exc()}")
376+
logger.error(f"Downloading failed for episode by id '{episode_id_str}', Unexpected Exception: {traceback.format_exc()}")
377377
self.progress.emit([episode_id_str, "Failed", [0, 100]])
378378
return False
379379

380380
def run(self):
381-
logger.debug(f"Download worker {self.name} is running ")
381+
logger.info(f"Download worker {self.name} is running ")
382382
while not self.__stop:
383383
item = self.__queue.get()
384384
attempt = 0
385385
if item[0] == "track":
386386
while attempt < config.get("max_retries"):
387-
logger.debug(f"Processing download for track by id '{item[1]}', Attempt: {attempt}")
387+
logger.info(f"Processing download for track by id '{item[1]}', Attempt: {attempt}")
388388
attempt = attempt + 1
389389
self.progress.emit([item[1], "Downloading", None])
390390
status = self.download_track(
@@ -403,7 +403,7 @@ def run(self):
403403

404404
elif item[0] == "episode":
405405
while attempt < config.get("max_retries"):
406-
logger.debug(f"Processing download for episode by id '{item[1]}', Attempt: {attempt}")
406+
logger.info(f"Processing download for episode by id '{item[1]}', Attempt: {attempt}")
407407
attempt = attempt + 1
408408
self.progress.emit([item[1], "Downloading", None])
409409
status = self.download_episode(

utils.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111

1212
def login_user(username: str, password: str, login_data_dir: str)->list:
13-
logger.debug(f"logging in user '{username[:4]}****@****.***'")
13+
logger.info(f"logging in user '{username[:4]}****@****.***'")
1414
# Check the username and if pickled sessionfile exists load the session and append
1515
# Returns: [Success: Bool, Session: Session, PicklePath: str, premium: Bool]
1616
sessobj_pikpath = os.path.join(login_data_dir, username+"_GUZpotifylogin.json")
1717
os.makedirs(os.path.dirname(sessobj_pikpath), exist_ok=True)
1818
if os.path.isfile(sessobj_pikpath):
19-
logger.debug(f"Session file exists for user, attempting to use it '{username[:4]}****@****.***'")
20-
logger.info("Restoring user session")
19+
logger.info(f"Session file exists for user, attempting to use it '{username[:4]}****@****.***'")
20+
logger.debug("Restoring user session")
2121
# Session exists try loading it
2222
try:
2323
config = Session.Configuration.Builder().set_stored_credential_file(sessobj_pikpath).build()
@@ -27,7 +27,7 @@ def login_user(username: str, password: str, login_data_dir: str)->list:
2727
session = Session.Builder(conf=config).stored_file(sessobj_pikpath).create()
2828
logger.debug("Session created")
2929
premium = True if session.get_user_attribute("type") == "premium" else False
30-
logger.debug(f"Login successful for user '{username[:4]}****@****.***'")
30+
logger.info(f"Login successful for user '{username[:4]}****@****.***'")
3131
return [True, session, sessobj_pikpath, premium]
3232
except (RuntimeError, Session.SpotifyAuthenticationException):
3333
logger.error(f"Failed logging in user '{username[:4]}****@****.***', invalid credentials")
@@ -36,14 +36,14 @@ def login_user(username: str, password: str, login_data_dir: str)->list:
3636
logger.error(f"Failed to login user '{username[:4]}****@****.***' due to unexpected error: {traceback.format_exc()}")
3737
return [False, None, "", False]
3838
else:
39-
logger.debug(f"Session file does not exist user '{username[:4]}****@****.***', attempting login with uname/pass")
39+
logger.info(f"Session file does not exist user '{username[:4]}****@****.***', attempting login with uname/pass")
4040
try:
41-
logger.debug(f"logging in user '{username[:4]}****@****.***'")
41+
logger.info(f"logging in user '{username[:4]}****@****.***'")
4242
config = Session.Configuration.Builder().set_stored_credential_file(sessobj_pikpath).build()
4343
print("logging in !")
4444
session = Session.Builder(conf=config).user_pass(username, password).create()
4545
premium = True if session.get_user_attribute("type") == "premium" else False
46-
logger.debug(f"Login successful for user '{username[:4]}****@****.***'")
46+
logger.info(f"Login successful for user '{username[:4]}****@****.***'")
4747
return [True, session, sessobj_pikpath, premium]
4848
except (RuntimeError, Session.SpotifyAuthenticationException):
4949
logger.error(f"Failed logging in user '{username[:4]}****@****.***', invalid credentials")
@@ -54,7 +54,7 @@ def login_user(username: str, password: str, login_data_dir: str)->list:
5454
return [False, None, "", False]
5555

5656
def remove_user(username: str, login_data_dir: str, config)->bool:
57-
logger.debug(f"Removing user '{username[:4]}****@****.***' from saved entries")
57+
logger.info(f"Removing user '{username[:4]}****@****.***' from saved entries")
5858
sessobj_pikpath = os.path.join(login_data_dir, username+"_GUZpotifylogin.json")
5959
if os.path.isfile(sessobj_pikpath):
6060
os.remove(sessobj_pikpath)
@@ -69,14 +69,14 @@ def remove_user(username: str, login_data_dir: str, config)->bool:
6969
removed = True
7070
break
7171
if removed:
72-
logger.debug(f"Saved Account user '{username[:4]}****@****.***' found and removed")
72+
logger.info(f"Saved Account user '{username[:4]}****@****.***' found and removed")
7373
config.set_("accounts", accounts_copy)
7474
config.update()
7575
return removed
7676

7777

7878
def regex_input_for_urls(search_input):
79-
logger.debug(f"Parsing url '{search_input}'")
79+
logger.info(f"Parsing url '{search_input}'")
8080
track_uri_search = re.search(
8181
r"^spotify:track:(?P<TrackID>[0-9a-zA-Z]{22})$", search_input)
8282
track_url_search = re.search(
@@ -165,22 +165,22 @@ def regex_input_for_urls(search_input):
165165
def get_url_data(url):
166166
track_id_str, album_id_str, playlist_id_str, episode_id_str, show_id_str, artist_id_str = regex_input_for_urls(url)
167167
if track_id_str is not None:
168-
logger.debug(f"Parse result for url '{url}'-> track, {track_id_str}")
168+
logger.info(f"Parse result for url '{url}'-> track, {track_id_str}")
169169
return "track", track_id_str
170170
elif album_id_str is not None:
171-
logger.debug(f"Parse result for url '{url}'-> album, {album_id_str}")
171+
logger.info(f"Parse result for url '{url}'-> album, {album_id_str}")
172172
return "album", album_id_str
173173
elif playlist_id_str is not None:
174-
logger.debug(f"Parse result for url '{url}'-> playlist, {playlist_id_str}")
174+
logger.info(f"Parse result for url '{url}'-> playlist, {playlist_id_str}")
175175
return "playlist", playlist_id_str
176176
elif episode_id_str is not None:
177-
logger.debug(f"Parse result for url '{url}'-> episode, {episode_id_str}")
177+
logger.info(f"Parse result for url '{url}'-> episode, {episode_id_str}")
178178
return "episode", episode_id_str
179179
elif show_id_str is not None:
180-
logger.debug(f"Parse result for url '{url}'-> podcast, {show_id_str}")
180+
logger.info(f"Parse result for url '{url}'-> podcast, {show_id_str}")
181181
return "podcast", show_id_str
182182
elif artist_id_str is not None:
183-
logger.debug(f"Parse result for url '{url}'-> artist, {artist_id_str}")
183+
logger.info(f"Parse result for url '{url}'-> artist, {artist_id_str}")
184184
return "artist", artist_id_str
185185
else:
186186
logger.error(f"Parse result for url '{url}' failed, invalid spotify url !")

0 commit comments

Comments
 (0)