B"H add playlist writing code
This commit is contained in:
parent
8226a35bc2
commit
de69905c54
2 changed files with 57 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
from mopidy import backend
|
from mopidy import backend
|
||||||
from mopidy_subidy import uri
|
from mopidy_subidy import uri
|
||||||
|
from mopidy.models import Playlist
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -15,10 +16,22 @@ class SubidyPlaylistsProvider(backend.PlaylistsProvider):
|
||||||
return self.playlists
|
return self.playlists
|
||||||
|
|
||||||
def create(self, name):
|
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:
|
||||||
|
self.refresh()
|
||||||
|
for pl in self.playlists:
|
||||||
|
if pl.name == name:
|
||||||
|
playlist = pl
|
||||||
|
return playlist
|
||||||
|
else:
|
||||||
|
return self.subsonic_api.raw_playlist_to_playlist(playlist)
|
||||||
|
|
||||||
def delete(self, uri):
|
def delete(self, playlist_uri):
|
||||||
pass
|
playlist_id = uri.get_playlist_id(playlist_uri)
|
||||||
|
self.subsonic_api.delete_playlist_raw(playlist_id)
|
||||||
|
|
||||||
def get_items(self, items_uri):
|
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))))
|
#logger.info('ITEMS %s: %s' % (lookup_uri, self.subsonic_api.get_playlist_songs_as_refs(uri.get_playlist_id(items_uri))))
|
||||||
|
@ -32,4 +45,11 @@ class SubidyPlaylistsProvider(backend.PlaylistsProvider):
|
||||||
self.playlists = self.subsonic_api.get_playlists_as_refs()
|
self.playlists = self.subsonic_api.get_playlists_as_refs()
|
||||||
|
|
||||||
def save(self, playlist):
|
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.update_playlist_raw(playlist_id, track_ids)
|
||||||
|
if result is None:
|
||||||
|
return None
|
||||||
|
return playlist
|
||||||
|
|
|
@ -101,6 +101,39 @@ class SubsonicApi():
|
||||||
albums=[self.raw_album_to_album(album) for album in result.get('album') or []],
|
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 []])
|
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 update_playlist_raw(self, playlist_id, song_ids):
|
||||||
|
try:
|
||||||
|
response = self.connection.updatePlaylist(playlist_id, songIdsToAdd=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):
|
def get_raw_artists(self):
|
||||||
try:
|
try:
|
||||||
response = self.connection.getArtists()
|
response = self.connection.getArtists()
|
||||||
|
|
Loading…
Add table
Reference in a new issue