Merge pull request #19 from hhm0/writable_playlists
Add playlist editing functionality
This commit is contained in:
commit
70b8245fd0
3 changed files with 59 additions and 8 deletions
|
@ -24,12 +24,11 @@ The following things are supported:
|
|||
|
||||
* Browsing all artists/albums/tracks
|
||||
* Searching for any terms
|
||||
* Browsing playlists
|
||||
* Browsing, creating, editing and deleting playlists
|
||||
* Searching explicitly for one of: artists, albums, tracks
|
||||
|
||||
The following things are **not** supported:
|
||||
|
||||
* Creating, editing and deleting playlists
|
||||
* Subsonics smart playlists
|
||||
* Searching for a combination of filters (artist and album, artist and track, etc.)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from mopidy import backend
|
||||
from mopidy_subidy import uri
|
||||
from mopidy.models import Playlist
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -12,13 +13,24 @@ class SubidyPlaylistsProvider(backend.PlaylistsProvider):
|
|||
self.refresh()
|
||||
|
||||
def as_list(self):
|
||||
return self.playlists
|
||||
return self.subsonic_api.get_playlists_as_refs()
|
||||
|
||||
def create(self, name):
|
||||
pass
|
||||
result = self.subsonic_api.create_playlist_raw(name)
|
||||
if result is None:
|
||||
return None
|
||||
playlist = result.get('playlist')
|
||||
if playlist is None:
|
||||
for pl in self.subsonic_api.get_playlists_as_playlists():
|
||||
if pl.name == name:
|
||||
playlist = pl
|
||||
return playlist
|
||||
else:
|
||||
return self.subsonic_api.raw_playlist_to_playlist(playlist)
|
||||
|
||||
def delete(self, uri):
|
||||
pass
|
||||
def delete(self, playlist_uri):
|
||||
playlist_id = uri.get_playlist_id(playlist_uri)
|
||||
self.subsonic_api.delete_playlist_raw(playlist_id)
|
||||
|
||||
def get_items(self, items_uri):
|
||||
#logger.info('ITEMS %s: %s' % (lookup_uri, self.subsonic_api.get_playlist_songs_as_refs(uri.get_playlist_id(items_uri))))
|
||||
|
@ -29,7 +41,14 @@ class SubidyPlaylistsProvider(backend.PlaylistsProvider):
|
|||
return self.subsonic_api.get_playlist_as_playlist(uri.get_playlist_id(lookup_uri))
|
||||
|
||||
def refresh(self):
|
||||
self.playlists = self.subsonic_api.get_playlists_as_refs()
|
||||
pass
|
||||
|
||||
def save(self, playlist):
|
||||
pass
|
||||
playlist_id = uri.get_playlist_id(playlist.uri)
|
||||
track_ids = []
|
||||
for trk in playlist.tracks:
|
||||
track_ids.append(uri.get_song_id(trk.uri))
|
||||
result = self.subsonic_api.save_playlist_raw(playlist_id, track_ids)
|
||||
if result is None:
|
||||
return None
|
||||
return playlist
|
||||
|
|
|
@ -102,6 +102,39 @@ class SubsonicApi():
|
|||
albums=[self.raw_album_to_album(album) for album in result.get('album') or []],
|
||||
tracks=[self.raw_song_to_track(song) for song in result.get('song') or []])
|
||||
|
||||
def create_playlist_raw(self, name):
|
||||
try:
|
||||
response = self.connection.createPlaylist(name=name)
|
||||
except Exception as e:
|
||||
logger.warning('Connecting to subsonic failed when creating playlist.')
|
||||
return None
|
||||
if response.get('status') != RESPONSE_OK:
|
||||
logger.warning('Got non-okay status code from subsonic: %s' % response.get('status'))
|
||||
return None
|
||||
return response
|
||||
|
||||
def delete_playlist_raw(self, playlist_id):
|
||||
try:
|
||||
response = self.connection.deletePlaylist(playlist_id)
|
||||
except Exception as e:
|
||||
logger.warning('Connecting to subsonic failed when deleting playlist.')
|
||||
return None
|
||||
if response.get('status') != RESPONSE_OK:
|
||||
logger.warning('Got non-okay status code from subsonic: %s' % response.get('status'))
|
||||
return None
|
||||
return response
|
||||
|
||||
def save_playlist_raw(self, playlist_id, song_ids):
|
||||
try:
|
||||
response = self.connection.createPlaylist(playlist_id, songIds=song_ids)
|
||||
except Exception as e:
|
||||
logger.warning('Connecting to subsonic failed when creating playlist.')
|
||||
return None
|
||||
if response.get('status') != RESPONSE_OK:
|
||||
logger.warning('Got non-okay status code from subsonic: %s' % response.get('status'))
|
||||
return None
|
||||
return response
|
||||
|
||||
def get_raw_artists(self):
|
||||
try:
|
||||
response = self.connection.getArtists()
|
||||
|
|
Loading…
Add table
Reference in a new issue