from __future__ import unicode_literals

import logging

from mopidy import backend
from mopidy.models import Playlist

logger = logging.getLogger(__name__)


class AmpachePlaylistsProvider(backend.PlaylistsProvider):
    def __init__(self, *args, **kwargs):
        super(AmpachePlaylistsProvider, self).__init__(*args, **kwargs)
        self.remote = self.backend.remote
        self.playlists = self._get_playlists()

    def lookup(self, uri):
        logger.debug('Playlist lookup. uri = %s' % uri)
        id = uri.split("ampache://")[1]
        try:
            id = int(id)
            return self.remote.playlist_id_to_playlist(id)
        except:
            if (id == 'randomsongs'):
                return self.remote.generate_random_playlist()
            else:
                return self.remote.get_smart_playlist(id)

    def _get_playlists(self):
        smart_playlists = {'random': 'Random Albums',
                           'newest': 'Recently Added',
                           'highest': 'Top Rated',
                           'frequent': 'Most Played',
                           'recent': 'Recently Played',
                           'randomsongs': 'Random Songs'}
        playlists = self.remote.get_user_playlists()
        for type in smart_playlists.keys():
            playlists.append(
                Playlist(
                    uri=u'ampache://%s' % type,
                    name='Smart Playlist: %s' % smart_playlists[type]))

        return playlists

Create playlist.py