Skip to content

Commit

Permalink
more support for playlist management
Browse files Browse the repository at this point in the history
  • Loading branch information
wendlers committed Oct 18, 2012
1 parent 978714e commit ab0d047
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
6 changes: 3 additions & 3 deletions doc/PyScMPDImplementation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ listplaylistinfo Yes Lists the songs with metadata in the
listplaylists No Prints a list of the playlist directory.
load Yes Loads the playlist into the current queue.
playlistadd No Adds track to a playlist.
playlistclear No Clears a playlist.
playlistdelete No Delete track from playlist.
playlistmove No Move songe in playlist.
playlistclear Yes Clears a playlist.
playlistdelete Yes Delete track from playlist.
playlistmove Yes Move songe in playlist.
rename Yes Rename a playlist.
rm Yes Remove a playlist.
save Yes Save a playlist.
Expand Down
9 changes: 9 additions & 0 deletions extlib/python-mpd-server/mpdserver/command_skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ class Save(Command):
class Rm(Command):
formatArg=[('playlistName',str)]

class PlaylistClear(Command):
formatArg=[('playlistName',str)]

class PlaylistMove(Command):
formatArg=[('playlistName',str), ('songId', int), ('songPos', int) ]

class PlaylistDelete(Command):
formatArg=[('playlistName',str), ('songPos', int) ]

class Rename(Command):
formatArg=[('playlistName',str), ('playlistNameNew',str)]

Expand Down
3 changes: 3 additions & 0 deletions extlib/python-mpd-server/mpdserver/mpdserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class MpdRequestHandler(SocketServer.StreamRequestHandler):
'previous' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
'random' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
'listplaylists' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
'playlistclear' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
'playlistmove' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
'playlistdelete' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
'load' :{'class':None,'users':[],'group':'write','mpdVersion':"0.12",'neededBy':None},
'save' :{'class':None,'users':[],'group':'write','mpdVersion':"0.12",'neededBy':None},
'search' :{'class':None,'users':[],'group':'read','mpdVersion':"0.12",'neededBy':None},
Expand Down
48 changes: 46 additions & 2 deletions src/pyscmpd/gstplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,16 @@ def setVolume(self, percent):
def getVolume(self):
return int(self.player.get_property('volume') * 100)

def storePlaylist(self, plName = CURR_PLAYLIST_KEY):
def storePlaylist(self, plName = CURR_PLAYLIST_KEY, playlist = None):

logging.info("Storing playlist with key: %s" % plName)

p = persist.ResourceFilePersistence(PLAYLIST_DIR)
p.store(plName, self.children)

if playlist == None:
p.store(plName, self.children)
else:
p.store(plName, playlist)

def retrivePlaylist(self, plName = CURR_PLAYLIST_KEY, makeCurrent = True):

Expand Down Expand Up @@ -390,3 +394,43 @@ def renamePlaylist(self, plNameSrc, plNameDst):
p = persist.ResourceFilePersistence(PLAYLIST_DIR)
p.rename(plNameSrc, plNameDst)

def playlistMove(self, plName, songId, songPos):

p = persist.ResourceFilePersistence(PLAYLIST_DIR)
c = p.retrive(plName)

if c == None:
loggin.warn("Unable to retrive playlist: %s" % plName)
return

try:
s = c[songId]

c.remove(s)
c.insert(songPos, s)

p.store(plName, c)

except:
logging.warn("Unable to move song with ID %i to position %i in playlist: %s" %
(songId, songPos, plName))

def playlistDelete(self, plName, songPos):

p = persist.ResourceFilePersistence(PLAYLIST_DIR)
c = p.retrive(plName)

if c == None:
loggin.warn("Unable to retrive playlist: %s" % plName)
return

try:

s = c[songPos]

c.remove(s)
p.store(plName, c)

except:
logging.warn("Unable to delete song at position %i in playlist: %s" % (songPos, plName))

18 changes: 18 additions & 0 deletions src/pyscmpd/scmpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites, serverPort
self.requestHandler.RegisterCommand(ListPlaylists)
self.requestHandler.RegisterCommand(Rm)
self.requestHandler.RegisterCommand(Rename)
self.requestHandler.RegisterCommand(PlaylistClear)
self.requestHandler.RegisterCommand(PlaylistMove)
self.requestHandler.RegisterCommand(PlaylistDelete)

self.requestHandler.Playlist = MpdPlaylist

Expand Down Expand Up @@ -379,6 +382,21 @@ def items(self):

return self.helper_status_stop()

class PlaylistClear(mpdserver.PlaylistClear):

def handle_args(self, playlistName):
ScMpdServerDaemon.player.storePlaylist(playlistName, [])

class PlaylistMove(mpdserver.PlaylistMove):

def handle_args(self, playlistName, songId, songPos):
ScMpdServerDaemon.player.playlistMove(playlistName, songId, songPos)

class PlaylistDelete(mpdserver.PlaylistDelete):

def handle_args(self, playlistName, songPos):
ScMpdServerDaemon.player.playlistDelete(playlistName, songPos)

class Save(mpdserver.Save):

def handle_args(self, playlistName):
Expand Down

0 comments on commit ab0d047

Please sign in to comment.