Permalink
Browse files

fixed bug for favorite-groups, cleaned up logging

  • Loading branch information...
1 parent 53b0de8 commit 17fc11a50d59bbf998059849dc57fe2a6c60ed8e @wendlers committed Oct 10, 2012
Showing with 80 additions and 79 deletions.
  1. +3 −3 doc/PyScMPDImplementation.txt
  2. +13 −0 src/pyscmpd/gstplayer.py
  3. +12 −8 src/pyscmpd/scmpd.py
  4. +52 −68 src/pyscmpd/scprovider.py
@@ -67,16 +67,16 @@ shuffle No Shuffle the current playlist.
swap No Swap two songs.
swapid No As above but ueses ids.
listplaylist No Lists the songs in the playlist.
-listplaylistinfo No Lists the songs with metadata in the playlist.
+listplaylistinfo Yes Lists the songs with metadata in the playlist.
listplaylists No Prints a list of the playlist directory.
-load No Loads the playlist into the current queue.
+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.
rename No Rename a playlist.
rm No Remove a playlist.
-save No Save a playlist.
+save Yes Save a playlist.
count No Counts the number of songs and their total playtime in the db.
find No Fins songs in the db.
findadd No Find songs in the db, add to playlist.
View
@@ -169,6 +169,19 @@ def getResourcePosInPlaylist(self, res, playlist):
return -1
+ def getIdPosInPlaylist(self, resId, playlist):
+
+ p = 0
+
+ for r in playlist:
+
+ if resId == r.getId():
+ return p
+
+ p = p + 1
+
+ return -1
+
def move(self, filePosFrom, filePosTo):
logging.debug("Move posFrom %d, posTo %d" % (filePosFrom, filePosTo))
View
@@ -169,7 +169,7 @@ def items(self):
else:
r = ScMpdServerDaemon.scroot.getChildByPath(self.directory)
- if not r.getType() == 1:
+ if r == None or not r.getType() == 1:
logging.warn("[%s] is not a directory" % r.getName())
return i
@@ -240,7 +240,7 @@ def handle_args(self, song):
ScMpdServerDaemon.player.addChild(t)
- logging.info("Successfully added song: %s" % t.__str__())
+ logging.info("Successfully added song: %s" % t.getName())
class AddId(mpdserver.AddId):
@@ -268,7 +268,11 @@ def items(self):
class MpdPlaylist(mpdserver.MpdPlaylist):
- def handlePlaylist(self):
+ def songIdToPosition(self, id):
+
+ return ScMpdServerDaemon.player.getIdPosInPlaylist(id, ScMpdServerDaemon.player.children)
+
+ def handlePlaylist(self):
# TODO: only recreate list if player indicates new playlist version
@@ -294,19 +298,19 @@ def handlePlaylist(self):
return pl
- def version(self):
+ def version(self):
return ScMpdServerDaemon.player.playlistVersion
- def move(self,fromPosition,toPosition):
+ def move(self,fromPosition,toPosition):
ScMpdServerDaemon.player.moveId(fromPosition, toPosition)
- def moveId(self,fromId,toPosition):
+ def moveId(self,fromId,toPosition):
ScMpdServerDaemon.player.moveId(fromId, toPosition)
- def delete(self, position):
+ def delete(self, position):
ScMpdServerDaemon.player.delete(position)
- def deleteId(self, songId):
+ def deleteId(self, songId):
ScMpdServerDaemon.player.deleteId(songId)
class Status(mpdserver.Status):
View
@@ -49,6 +49,12 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
resource.DirectoryResource.__init__(self, 0, "pyscmpd", "pyscmpd")
+ self.__populateFavoriteUsers(favoriteUsers)
+ self.__populateFavoriteGroups(favoriteGroups)
+ self.__populateFavoriteFavorites(favoriteFavorites)
+
+ def __populateFavoriteUsers(self, favoriteUsers):
+
ufavgrp = "users"
ufav = resource.DirectoryResource(0, ufavgrp, ufavgrp)
ufav.setMeta({"directory" : ufavgrp})
@@ -57,13 +63,31 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
f = FavoriteUsers(fav["name"], fav["users"], ufavgrp)
ufav.addChild(f)
+ self.addChild(ufav)
+
+ def __populateFavoriteGroups(self, favoriteGroups):
+
gfavgrp = "groups"
gfav = resource.DirectoryResource(0, gfavgrp, gfavgrp)
gfav.setMeta({"directory" : gfavgrp})
for fav in favoriteGroups:
- f = FavoriteGroups(fav["name"], fav["groups"], gfavgrp)
- gfav.addChild(f)
+
+ logging.info("Adding new favorites folder [%s] with groups [%s]" %
+ (fav["name"], fav["groups"]))
+
+ d = resource.DirectoryResource(0, gfavgrp + "/" + fav["name"], fav["name"])
+ d.setMeta({"directory" : gfavgrp + "/" + fav["name"]})
+
+ for group in fav["groups"]:
+ g = Group(-1, group, gfavgrp + "/" + fav["name"])
+ d.addChild(g)
+
+ gfav.addChild(d)
+
+ self.addChild(gfav)
+
+ def __populateFavoriteFavorites(self, favoriteFavorites):
ffavgrp = "favorites"
ffav = resource.DirectoryResource(0, ffavgrp, ffavgrp)
@@ -84,8 +108,6 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
ffav.addChild(d)
- self.addChild(ufav)
- self.addChild(gfav)
self.addChild(ffav)
class FavoriteUsers(resource.DirectoryResource):
@@ -120,7 +142,7 @@ def getAllChildren(self):
def retriveChildren(self):
- self.children = []
+ children = []
for uname in self.users:
@@ -133,70 +155,15 @@ def retriveChildren(self):
u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
- self.addChild(u)
+ children.append(u)
logging.info("Successfully retrieved data for URI %s: id=%d; name=%s" %
(uname, u.getId(), user.permalink))
except Exception as e:
logging.warn("Unable to retrive data for URI %s: %s" % (uname, `e`))
-class FavoriteGroups(resource.DirectoryResource):
-
- retriveLock = None
- groups = None
- category = None
-
- def __init__(self, name, groups, category):
-
- logging.info("Adding new favorites folder [%s] with groups [%s]" %
- (name, groups))
-
- resource.DirectoryResource.__init__(self, 0, name, name)
-
- self.category = category
- self.children = None
- self.groups = groups
- self.retriveLock = Lock()
-
- self.setMeta({"directory" : self.category + "/" + self.name})
-
- def getAllChildren(self):
-
- self.retriveLock.acquire()
-
- if self.children == None:
- self.retriveChildren()
-
- self.retriveLock.release()
-
- return self.children
-
- def retriveChildren(self):
-
- self.children = []
-
- for gname in self.groups:
-
- try:
-
- group = ResourceProvider.sc.get("/resolve", url="http://soundcloud.com/groups/%s" %
- self.name)
-
- users = ResourceProvider.sc.get("/groups/%d/users" % group.id)
-
- for user in users:
- u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink,
- user.username, self.category + "/" + self.name)
-
- u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
- self.addChild(u)
-
- logging.info("Successfully retrieved user data: id=%d; name=%s" %
- (u.getId(), user.permalink))
-
- except Exception as e:
- logging.warn("Unable to retrive data for groups: %s" % `e`)
+ self.children = children
class Group(resource.DirectoryResource):
@@ -229,24 +196,39 @@ def getAllChildren(self):
def retriveChildren(self):
- self.children = []
- groupId = self.getId() - resource.ID_OFFSET
+ children = []
try:
+
+ if self.getId() == -1:
+ group = ResourceProvider.sc.get("/resolve",
+ url="http://soundcloud.com/groups/%s" %
+ self.name)
+
+ self.id = group.id
+ groupId = self.id
+ else:
+ groupId = self.getId() - resource.ID_OFFSET
+
users = ResourceProvider.sc.get("/groups/%d/users" % groupId)
for user in users:
+
u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink, user.username,
self.category + "/" + self.name)
+
u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
- self.addChild(u)
+
+ children.append(u)
logging.info("Successfully retrieved user data: id=%d; name=%s" %
(u.getId(), user.permalink))
except Exception as e:
logging.warn("Unable to retrive data for group %d: %s" % (groupId, `e`))
+ self.children = children
+
class User(resource.DirectoryResource):
retriveLock = None
@@ -276,7 +258,7 @@ def getAllChildren(self):
def retriveChildren(self):
- self.children = []
+ children = []
try:
@@ -290,15 +272,17 @@ def retriveChildren(self):
"Title" : track.title,
"Time" : track.duration})
- self.addChild(tr)
+ children.append(tr)
logging.debug("Added track to user [%s]: %s" % (self.getName(), track.title))
except Exception as e:
logging.warn("Unable to retrive tracks for [%s]" % self.getName())
- logging.info("Retrieved %d tracks for user [%s]" % (len(self.children), self.getName()))
+ logging.info("Retrieved %d tracks for user [%s]" % (len(children), self.getName()))
+
+ self.children = children
class Track(resource.FileResource):

0 comments on commit 17fc11a

Please sign in to comment.