Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first try for favorite groups

  • Loading branch information...
commit be3a4a2584117a36b2550e0de79680526451a52f 1 parent 2687c3a
@wendlers authored
Showing with 66 additions and 7 deletions.
  1. +1 −1  src/pyscmpd/pyscmpdctrl.py
  2. +65 −6 src/pyscmpd/scprovider.py
View
2  src/pyscmpd/pyscmpdctrl.py
@@ -53,7 +53,7 @@ def prepare():
f.write("gethoswing : maddecent, barelylegit\n")
f.write("electrosoul: griz\n")
f.write("\n[favorite-groups]\n")
- f.write("groups: deep-house-4, minimal-tech-hous\n")
+ f.write("groups: deep-house-4, minimal-tech-house\n")
f.close()
try:
View
71 src/pyscmpd/scprovider.py
@@ -51,22 +51,30 @@ def __init__(self, favoriteUsers, favoriteGroups):
uall = Users("random-users")
- favgrp = "favorite-users"
- ufav = resource.DirectoryResource(0, favgrp ,favgrp )
- ufav.setMeta({"directory" : favgrp})
+ ufavgrp = "favorite-users"
+ ufav = resource.DirectoryResource(0, ufavgrp, ufavgrp )
+ ufav.setMeta({"directory" : ufavgrp})
for fav in favoriteUsers:
- f = FavoriteUsers(fav["name"], fav["users"], favgrp)
+ f = FavoriteUsers(fav["name"], fav["users"], ufavgrp)
ufav.addChild(f)
grps = Groups("random-groups")
+
+ gfavgrp = "favorite-groups"
+ gfav = resource.DirectoryResource(0, gfavgrp, gfavgrp )
+ gfav.setMeta({"directory" : gfavgrp})
+
for fav in favoriteGroups:
logging.info("Adding favorite group: %s" % fav)
+ f = FavoriteGroup(fav, gfavgrp)
+ gfav.addChild(f)
self.addChild(ufav)
self.addChild(uall)
self.addChild(grps)
+ self.addChild(gfav)
class Users(resource.DirectoryResource):
@@ -158,7 +166,8 @@ def retriveChildren(self):
try:
user = ResourceProvider.sc.get("/users/" + uri)
- u = User(resource.ID_OFFSET + user.id, user.uri, user.permalink, user.username, self.category + "/" + self.name)
+ u = User(resource.ID_OFFSET + user.id, user.uri, user.permalink, user.username,
+ self.category + "/" + self.name)
u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
self.addChild(u)
@@ -168,6 +177,56 @@ def retriveChildren(self):
except Exception as e:
logging.warn("Unable to retrive data for URI %s: %s" % (uri, `e`))
+class FavoriteGroup(resource.DirectoryResource):
+
+ retriveLock = None
+ category = None
+
+ def __init__(self, name, category):
+
+ resource.DirectoryResource.__init__(self, 0, name, name)
+
+ self.category = category
+ self.children = None
+ 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 = []
+
+ 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, 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`)
+
+
class Groups(resource.DirectoryResource):
retriveLock = None
@@ -199,7 +258,7 @@ def retriveChildren(self):
self.children = []
try:
-
+
groups = ResourceProvider.sc.get("/groups")
for group in groups:
Please sign in to comment.
Something went wrong with that request. Please try again.