Skip to content

Commit

Permalink
Get playlist names in foreground, tracks in background
Browse files Browse the repository at this point in the history
  • Loading branch information
kingosticks committed Apr 12, 2024
1 parent e2fea50 commit 6ae154d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
44 changes: 16 additions & 28 deletions mopidy_spotify/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,22 @@ def _refresh_tracks(self, playlist_uris):
if not self._refresh_mutex.locked():
logger.error("Lock must be held before calling this method")
return []
with utils.time_logger("playlists._refresh_tracks()", logging.DEBUG):
refreshed = [uri for uri in playlist_uris if self.lookup(uri)]
logger.info(f"Refreshed {len(refreshed)} Spotify playlists")

logger.info("Refreshing Spotify playlists")

def refresher():
try:
with utils.time_logger("playlists.refresh()", logging.DEBUG):
self._backend._web_client.clear_cache()
count = 0
for playlist_ref in self._get_flattened_playlist_refs():
self._get_playlist(playlist_ref.uri)
count += 1
logger.info(f"Refreshed {count} Spotify playlists")

listener.CoreListener.send("playlists_loaded")
self._loaded = True
except Exception:
logger.exception(
"An error occurred while refreshing Spotify playlists"
)
finally:
self._refreshing = False

thread = threading.Thread(target=refresher)
thread.daemon = True
thread.start()
try:
with utils.time_logger(
"playlists._refresh_tracks()", logging.DEBUG
):
refreshed = [uri for uri in playlist_uris if self.lookup(uri)]
logger.info(f"Refreshed {len(refreshed)} Spotify playlists")

listener.CoreListener.send("playlists_loaded")
except Exception:
logger.exception(
"Error occurred while refreshing Spotify playlists tracks"
)
else:
return refreshed # For test
finally:
self._refresh_mutex.release()

def create(self, name):
pass # TODO
Expand Down
1 change: 1 addition & 0 deletions mopidy_spotify/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from enum import Enum, unique
from typing import Optional


import requests

from mopidy_spotify import utils
Expand Down

0 comments on commit 6ae154d

Please sign in to comment.