| 123456789101112131415161718192021222324252627282930313233343536 |
- from mopidy.models import Playlist, Track
- from mopidy.backend import PlaylistProvider
- from .mb_client import get_similar_artists, get_genre_tracks
- class SmartPlaylistsProvider(PlaylistProvider):
- def as_list(self):
- playlists = []
- # Genres
- for genre in ["rock", "jazz", "hiphop", "blues"]:
- playlists.append(
- Playlist(uri=f"smart:genre:{genre}", name=f"Genre: {genre.title()}")
- )
- # Example artist radios
- playlists.append(
- Playlist(uri="smart:artist:radio:MBID123", name="Artist Radio: Example")
- )
- return playlists
- def lookup(self, uri):
- parts = uri.split(":")
- typ = parts[1]
- if typ == "genre":
- genre = parts[2]
- tracks = get_genre_tracks(genre)
- elif typ == "artist" and parts[2] == "radio":
- mbid = parts[3]
- tracks = get_similar_artists(mbid)
- else:
- return None
- return Playlist(uri=uri, name="Generated", tracks=tracks)
|