rattboi / mopidy-subsonic

Mopidy backend extension for playing music from Subsonic Music Streamer
MIT License
17 stars 14 forks source link

Fails to connect to subsonic client if server returns empty playlists #8

Closed cbomgit closed 9 years ago

cbomgit commented 9 years ago

Found this problem on Arch Linux x64, python2-pysonic 0.2.2-1, and mopidy-subsonic 0.3.1-1.

The problem code is here:

def get_user_playlists(self):
    results = self.api.getPlaylists().get('playlists')
    if results is u'':
        return []
    else:
        results = makelist(unescapeobj(self.api.getPlaylists().get('playlists').get('playlist')))
        return [Playlist(uri=u'subsonic://%s' % playlist.get('id'),
                     name='User Playlist: %s' % self.fix_playlist_name(playlist.get('name')))
                     for playlist in results]

If the subsonic server returns a dict with an empty 'playlists' key, the check at the beginning of the function will still fail. It should instead check for an empty list with 'if not results':

def get_user_playlists(self):
    results = self.api.getPlaylists().get('playlists')
    if not results:
        return []
    else:
        results = makelist(unescapeobj(self.api.getPlaylists().get('playlists').get('playlist')))
        return [Playlist(uri=u'subsonic://%s' % playlist.get('id'),
                     name='User Playlist: %s' % self.fix_playlist_name(playlist.get('name')))
                     for playlist in results]

Thanks!

Primal-id commented 9 years ago

ERROR Uncaught exception Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/mopidy/commands.py", line 272, in run backends = self.start_backends(config, backend_classes, audio) File "/usr/lib/python2.7/dist-packages/mopidy/commands.py", line 343, in start_backends config=config, audio=audio).proxy() File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 93, in start obj = cls(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/actor.py", line 32, in init self.playlists = SubsonicPlaylistsProvider(backend=self) File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/playlist.py", line 15, in init self.playlists = self._get_playlists() File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/playlist.py", line 36, in _get_playlists playlists = self.remote.get_user_playlists() File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/client.py", line 360, in get_user_playlists for playlist in results] AttributeError: 'NoneType' object has no attribute 'get'

matt7277 commented 9 years ago

I am having this issue as well on my pi music box: 2015-04-01 01:50:08,285 - INFO Connecting to Subsonic library http://example.subsonic.net:4040 as user ExampleUser 2015-04-01 01:50:08,344 - ERROR Uncaught exception Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/mopidy/commands.py", line 272, in run backends = self.start_backends(config, backend_classes, audio) File "/usr/local/lib/python2.7/dist-packages/mopidy/commands.py", line 343, in start_backends config=config, audio=audio).proxy() File "/usr/lib/python2.7/dist-packages/pykka/actor.py", line 93, in start obj = cls(_args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/actor.py", line 32, in init self.playlists = SubsonicPlaylistsProvider(backend=self) File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/playlist.py", line 15, in init self.playlists = self._get_playlists() File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/playlist.py", line 36, in _get_playlists playlists = self.remote.get_user_playlists() File "/usr/local/lib/python2.7/dist-packages/mopidy_subsonic/client.py", line 360, in get_user_playlists for playlist in results] AttributeError: 'NoneType' object has no attribute 'get' 2015-04-01 01:50:08,350 - INFO Stopping Mopidy frontends 2015-04-01 01:50:08,351 - INFO Stopping Mopidy core 2015-04-01 01:50:08,352 - INFO Stopping Mopidy backends

matt7277 commented 9 years ago

Anyone able to work around this problem? I'd love to be able to use my Subsonic service with Mopidy :+1:

rattboi commented 9 years ago

Sorry. I haven't been using Subsonic recently, so it may take a day or two to set up the testing environment again. I'm planning on working on this tomorrow.

If you need a solution right now, just make 1 playlist via the normal subsonic web interface.

hhm0 commented 7 years ago

Got it working in https://github.com/hhm0/mopidy-subsonic/tree/playnonefix; however, this only makes mopidy stop erroring, while the error might be a symptom of a larger problem. I would want to fix the bigger problem, if there is one, instead of just patching over the error, before submitting a pull request.

Perhaps #1 is connected to this.