Permalink
Browse files

prepared for favorite-favorites

  • Loading branch information...
1 parent c710e58 commit d99bbb65128d999de79761c891da6c1f2fc805aa @wendlers committed Oct 4, 2012
Showing with 59 additions and 20 deletions.
  1. +11 −1 etc/pyscmpd.conf
  2. +16 −5 src/pyscmpd/daemon.py
  3. +2 −0 src/pyscmpd/pyscmpdctrl.py
  4. +3 −2 src/pyscmpd/scmpd.py
  5. +27 −12 src/pyscmpd/scprovider.py
View
@@ -37,8 +37,18 @@ worldtrance : gogmusic
##
# Favorite groups
#
-# format: groups: <group1>, <user2>, ...
+# format: groups: <group1>, <group2>, ...
##
[favorite-groups]
groups: deep-house-4, minimal-tech-house
+
+##
+# Favorite favorites
+#
+# format: favorites: <user1>, <user2>, ...
+##
+[favorite-favorites]
+
+favorites: kaltpost
+
View
@@ -46,8 +46,9 @@ class PyScMpd:
mainloop = None
port = 9900
- favoriteUsers = None
- favoriteGroups = None
+ favoriteUsers = None
+ favoriteGroups = None
+ favoriteFavorites = None
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
@@ -56,8 +57,9 @@ def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/
self.stderr = stderr
self.pidfile = pidfile
- self.favoriteUsers = []
- self.favoriteGroups = []
+ self.favoriteUsers = []
+ self.favoriteGroups = []
+ self.favoriteFavorites = []
def daemonize(self):
@@ -243,6 +245,14 @@ def readConfig(self, cfgFile, foreground=False):
for group in groupsRaw:
self.favoriteGroups.append(group.strip())
+ if parser.has_option("favorite-favorites", "favorites"):
+
+ favoritesRaw = parser.get("favorite-favorites", "favorites").split(",")
+ favorites = []
+
+ for favorite in favoritesRaw:
+ self.favoriteFavorites.append(favorite.strip())
+
except Exception as e:
logging.warn("Unable to parsre config [%s]: %s" % (cfgFile, `e`))
@@ -251,7 +261,8 @@ def readConfig(self, cfgFile, foreground=False):
def run(self):
logging.info("pyscmpd v%s started" % PYSCMPD_VERSION)
- mpd = scmpd.ScMpdServerDaemon(self.favoriteUsers, self.favoriteGroups, self.port)
+ mpd = scmpd.ScMpdServerDaemon(self.favoriteUsers, self.favoriteGroups,
+ self.favoriteFavorites, self.port)
self.mainloop = gobject.MainLoop()
self.mainloop.run()
@@ -54,6 +54,8 @@ def prepare():
f.write("electrosoul: griz\n")
f.write("\n[favorite-groups]\n")
f.write("groups: deep-house-4, minimal-tech-house\n")
+ f.write("\n[favorite-favorites]\n")
+ f.write("favorites: kaltpost\n")
f.close()
try:
View
@@ -34,10 +34,11 @@ class ScMpdServerDaemon(mpdserver.MpdServerDaemon):
scroot = None
player = None
- def __init__(self, favoriteUsers, favoriteGroups, serverPort = 9900):
+ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites, serverPort = 9900):
ScMpdServerDaemon.player = gstplayer.GstPlayer()
- ScMpdServerDaemon.scp = provider.ResourceProvider(favoriteUsers, favoriteGroups)
+ ScMpdServerDaemon.scp = provider.ResourceProvider(favoriteUsers, favoriteGroups,
+ favoriteFavorites)
ScMpdServerDaemon.scroot = ScMpdServerDaemon.scp.getRoot()
mpdserver.MpdServerDaemon.__init__(self, serverPort)
View
@@ -33,26 +33,26 @@ class ResourceProvider:
sc = None
root = None
- def __init__(self, favoriteUsers, favoriteGroups):
+ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
ResourceProvider.sc = soundcloud.Client(client_id='aa13bebc2d26491f7f8d1e77ae996a64')
- self.root = Root(favoriteUsers, favoriteGroups)
+ self.root = Root(favoriteUsers, favoriteGroups, favoriteFavorites)
def getRoot(self):
return self.root
class Root(resource.DirectoryResource):
- def __init__(self, favoriteUsers, favoriteGroups):
+ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
resource.DirectoryResource.__init__(self, 0, "pyscmpd", "pyscmpd")
uall = Users("random-users")
ufavgrp = "favorite-users"
- ufav = resource.DirectoryResource(0, ufavgrp, ufavgrp )
+ ufav = resource.DirectoryResource(0, ufavgrp, ufavgrp)
ufav.setMeta({"directory" : ufavgrp})
for fav in favoriteUsers:
@@ -63,18 +63,32 @@ def __init__(self, favoriteUsers, favoriteGroups):
gfavgrp = "favorite-groups"
- gfav = resource.DirectoryResource(0, gfavgrp, gfavgrp )
+ 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)
+
+ '''
+ ffavgrp = "favorite-favorites"
+ ffav = FavoriteFavorites(favoriteFavorites, ffavgrp)
+ '''
+
+ ffavgrp = "favorite-favorites"
+ ffav = resource.DirectoryResource(0, ffavgrp, ffavgrp)
+ ffav.setMeta({"directory" : ffavgrp})
+
+ for fav in favoriteFavorites:
+ logging.info("Adding favorite favorite: %s" % fav)
+
self.addChild(ufav)
self.addChild(uall)
self.addChild(grps)
self.addChild(gfav)
+ self.addChild(ffav)
class Users(resource.DirectoryResource):
@@ -128,24 +142,23 @@ def retriveChildren(self):
class FavoriteUsers(resource.DirectoryResource):
- retriveLock = None
- users = None
- category = None
+ retriveLock = None
+ users = None
+ category = None
def __init__(self, name, users, category):
logging.info("Adding new favorites folder [%s] with users [%s]" %
(name, users))
resource.DirectoryResource.__init__(self, 0, name, name)
+ self.setMeta({"directory" : category + "/" + name})
self.category = category
self.children = None
self.users = users
self.retriveLock = Lock()
- self.setMeta({"directory" : self.category + "/" + self.name})
-
def getAllChildren(self):
self.retriveLock.acquire()
@@ -166,14 +179,16 @@ 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.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
+
self.addChild(u)
-
logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
(uri, u.getId(), user.permalink))
-
+
except Exception as e:
logging.warn("Unable to retrive data for URI %s: %s" % (uri, `e`))

0 comments on commit d99bbb6

Please sign in to comment.