Musicbox spotify playlists not there?

Hey folks

This has been consistently hitting me for the past few weeks now, and none of the previous solutions have worked for me (although it did look like maybe there’s an issue with MB0.6.0 where it erroneously sets the spotify cache_dir to “”, which prevents caching from what I could see).

After some digging, I’ve come to the belief that the reason this is an occasional issue is down to this piece of code in mopidy_spotify/session_manager.py:

def log_message(self, session, data):
    """Callback used by pyspotify"""
    logger.debug('System message: %s' % data.strip())
    if 'offline-mgr' in data and 'files unlocked' in data:
        # XXX This is a very very fragile and ugly hack, but we get no
        # proper event when libspotify is done with initial data loading.
        # We delay the expensive refresh of Mopidy's playlists until this
        # message arrives. This way, we avoid doing the refresh once for
        # every playlist or other change. This reduces the time from
        # startup until the Spotify backend is ready from 35s to 12s in one
        # test with clean Spotify cache. In cases with an outdated cache
        # the time improvements should be a lot greater.
        if not self._initial_data_receive_completed:
            self._initial_data_receive_completed = True
            self.refresh_playlists()

...

def refresh_playlists(self):
    """Refresh the playlists in the backend with data from Spotify"""
    if not self._initial_data_receive_completed:
        logger.debug('Still getting data; skipped refresh of playlists')
        return

The issue is that the initial data receive completed flag NEVER seems to be set. As the comment says, this is incredibly fragile, which is likely why this issue randomly appears and disappears!

I’m going to try locally to add a timeout to the logic - after 20s, just assume that the initial data receive has been completed and start returning playlists.

I think there are two things that would help here though -

  1. Make the system more robust (!!)
  2. Change the log message about skipping returning playlists to be INFO level, so it appears in logs by default, as it’s so catastrophic when it goes wrong, and at least that would allow people to diagnose it more easily