Skip to content

Commit

Permalink
Fix login credentials in local dir bug
Browse files Browse the repository at this point in the history
  • Loading branch information
justin025 committed Oct 24, 2024
1 parent c6f7346 commit ee02b05
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/onthespot/api/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def spotify_login_user(account):
config = Session.Configuration.Builder().set_stored_credential_file(session_json_path).build()
# For some reason initialising session as None prevents premature application exit
session = None
session = Session.Builder().stored_file(session_json_path).create()
session = Session.Builder(conf=config).stored_file(session_json_path).create()
logger.debug("Session created")
logger.info(f"Login successful for user '{username[:4]}*******'")
account_type = session.get_user_attribute("type")
Expand Down Expand Up @@ -309,9 +309,6 @@ def spotify_get_search_results(session, search_term, content_types):
logger.info(
f"Get search result for term '{search_term}'"
)
if search_term.strip() == "":
logger.warning(f"Returning empty data as query is empty !")
return ''
if content_types is None:
content_types = ["track", "album", "playlist", "artist", "show", "episode", "audiobook"]
token = session.tokens().get("user-read-email")
Expand Down
15 changes: 7 additions & 8 deletions src/onthespot/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ def __init__(self, gui=False):

def run(self):
while True:
download_delay = config.get("download_delay")
if download_queue:
try:
try:
try:
item = download_queue.pop(next(iter(download_queue)))
item_service = item['item_service']
item_type = item['item_type']
Expand All @@ -44,7 +43,7 @@ def run(self):
self.tr("Downloaded"),
self.tr("Already Exists")
):
time.sleep(1)
time.sleep(0.2)
continue
except (RuntimeError, OSError):
# Item likely cleared from download queue.
Expand All @@ -57,7 +56,7 @@ def run(self):

try:
item_metadata = globals()[f"{item_service}_get_{item_type}_metadata"](token, item_id)

item_path = format_track_path(item_metadata, item_service, item_type, item['is_playlist_item'], item['playlist_name'], item['playlist_by'])

except (Exception, KeyError):
Expand All @@ -72,7 +71,7 @@ def run(self):
os.makedirs(os.path.dirname(file_path), exist_ok=True)

item['file_path'] = file_path

# Skip file if exists under different extension
file_directory = os.path.dirname(file_path)
base_file_path = os.path.splitext(os.path.basename(file_path))[0]
Expand All @@ -86,7 +85,7 @@ def run(self):
if item['gui']['status_label'].text() == self.tr("Downloading"):
self.progress.emit(item, self.tr("Already Exists"), 100) # Emit progress
logger.info(f"File already exists, Skipping download for track by id '{item_id}'")
time.sleep(download_delay)
time.sleep(0.2)
continue
except FileNotFoundError:
logger.info(f"File does not already exist.")
Expand Down Expand Up @@ -203,10 +202,10 @@ def run(self):

if self.gui:
self.progress.emit(item, self.tr("Downloaded"), 100)
time.sleep(download_delay)
time.sleep(config.get("download_delay"))
except Exception as e:
self.progress.emit(item, self.tr("Failed"), 0)
logger.error(f"Unknown Exception: {str(e)}")
continue
else:
time.sleep(download_delay)
time.sleep(0.2)
2 changes: 1 addition & 1 deletion src/onthespot/gui/mainui.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def fill_search_table(self):
self.inp_search_term.setText('')
return
elif results is False:
self.__splash_dialog.run(self.tr("Invalid item, please check your account settings"))
self.__splash_dialog.run(self.tr("Invalid item, please check your query or account settings"))
self.inp_search_term.setText('')
return

Expand Down
4 changes: 4 additions & 0 deletions src/onthespot/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def get_search_results(search_term, content_types=None):
if len(account_pool) <= 0:
return None

if search_term == '':
logger.warning(f"Returning empty data as query is empty !")
return False

if search_term.startswith('https://'):
logger.info(f"Search clicked with value with url {search_term}")
result = parse_url(search_term)
Expand Down

0 comments on commit ee02b05

Please sign in to comment.