Permalink
Browse files

reintroduced random groups and users

  • Loading branch information...
1 parent d62848b commit 105576c476894cb4db3329ced1c548c37124af82 @wendlers committed Oct 22, 2012
Showing with 111 additions and 2 deletions.
  1. +4 −2 README.md
  2. +107 −0 src/pyscmpd/scprovider.py
View
@@ -20,10 +20,12 @@ Main features currently supported:
* Browse predefined set of favorite users (see "~/.pyscmpd/pyscmpd.conf")
* Browse predefined set of favorite groups (see "~/.pyscmpd/pyscmpd.conf")
* Browse the favorite tracks of a predefined set of users (see "~/.pyscmpd/pyscmpd.conf")
+* BRowse random users/groups
* Current playlist is persisted on SIGTERM and restored on next restart
-* Save current playlist to defined name (I needed to remove random-groups/users for this, since otherwise songs will not be found again)
-* Browse/Load playlists (only ncmpcpp yet, since sonata uses different command)
+* Save current playlist to defined name
+* Browse/Load playlists
* Add tracks to current play-list
+* Add tracks to named play-list
* Play tracks from play-list
* Change song order in current play-list
* Remove songs from play-list
View
@@ -52,6 +52,7 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
self.__populateFavoriteUsers(favoriteUsers)
self.__populateFavoriteGroups(favoriteGroups)
self.__populateFavoriteFavorites(favoriteFavorites)
+ self.__populateRandom()
def __populateFavoriteUsers(self, favoriteUsers):
@@ -110,6 +111,15 @@ def __populateFavoriteFavorites(self, favoriteFavorites):
self.addChild(ffav)
+ def __populateRandom(self):
+
+ d = resource.DirectoryResource(0, "random", "random")
+ d.setMeta({"directory" : "random"})
+ d.addChild(RandomGroups("random", "groups"))
+ d.addChild(RandomUsers("random", "users"))
+
+ self.addChild(d)
+
class FavoriteUsers(resource.DirectoryResource):
retriveLock = None
@@ -165,6 +175,103 @@ def retriveChildren(self):
self.children = children
+class RandomGroups(resource.DirectoryResource):
+
+ retriveLock = None
+ category = None
+
+ def __init__(self, category, name):
+
+ resource.DirectoryResource.__init__(self, 0, category, name)
+
+ self.category = category
+ self.children = None
+ self.retriveLock = Lock()
+
+ self.setMeta({"directory" : self.category + "/" + name})
+
+ def getAllChildren(self):
+
+ self.retriveLock.acquire()
+
+ if self.children == None:
+ self.retriveChildren()
+
+ self.retriveLock.release()
+
+ return self.children
+
+ def retriveChildren(self):
+
+ self.children = []
+
+ try:
+
+ groups = ResourceProvider.sc.get("/groups")
+
+ for group in groups:
+ logging.info("processing group %s" % group.permalink)
+ g = Group(resource.ID_OFFSET + group.id, group.permalink, self.category + "/" + self.name)
+ g.setMeta({"directory" : self.category + "/" + self.name + "/"
+ + group.permalink})
+ self.addChild(g)
+
+ logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
+ (group.uri, g.getId(), group.permalink))
+ except Exception as e:
+ logging.warn("Unable to retrive data for groups: %s" % `e`)
+
+class RandomUsers(resource.DirectoryResource):
+
+ category = None
+ retriveLock = None
+
+ def __init__(self, category, name):
+
+ resource.DirectoryResource.__init__(self, 0, category, name)
+
+ self.setMeta({"directory" : category + "/" + name})
+
+ self.category = category
+ self.children = None
+ self.retriveLock = Lock()
+
+ def getAllChildren(self):
+
+ self.retriveLock.acquire()
+
+ if self.children == None:
+ self.retriveChildren()
+
+ self.retriveLock.release()
+ return self.children
+
+ def retriveChildren(self):
+
+ self.children = []
+
+ try:
+ allUsers = ResourceProvider.sc.get("/users")
+
+ for user in allUsers:
+
+ try:
+
+ 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 data for URI %s: id=%d; name=%s" %
+ (user.uri, u.getId(), user.permalink))
+
+ except Exception as e:
+ logging.warn("Unable to retrive data for user: %s" % `e`)
+
+ except Exception as e:
+ logging.warn("Unable to retrive data for URI users: %s" % `e`)
+
class Group(resource.DirectoryResource):
retriveLock = None

0 comments on commit 105576c

Please sign in to comment.