Skip to content
Browse files

reworked favorites

  • Loading branch information...
1 parent 162398e commit 53b0de8ab332e9b6eab860204fcadd68b71b6df1 @wendlers committed
Showing with 99 additions and 174 deletions.
  1. +17 −10 README.md
  2. +5 −6 etc/pyscmpd.conf
  3. +18 −10 src/pyscmpd/daemon.py
  4. +6 −6 src/pyscmpd/gstplayer.py
  5. +3 −3 src/pyscmpd/pyscmpdctrl.py
  6. +1 −1 src/pyscmpd/resource.py
  7. +2 −2 src/pyscmpd/scmpd.py
  8. +47 −136 src/pyscmpd/scprovider.py
View
27 README.md
@@ -215,9 +215,11 @@ __Favorite Users__
To modify the list of your favorite users to browse, edit the *[favorite-users]* section
in "~/.pyscmpd/pyscmp.conf". The format used for favorite users is:
- category: user1, user2, ...
+ category1: user1, user2, ...
+ category2: user1, user2, ...
+ ...
-*category* is then shown in the browser as subfolder folder of *favorite-users* folder, containing all
+*categoryN* is then shown in the browser as subfolder folder of *users* folder, containing all
the users specified. *userN* is the user name of a soundcloud user as shown in the URL. E.g.
"griz" for [GRiZ] (http://soundcloud.com/griz).
@@ -226,20 +228,23 @@ __Favorite Groups__
To define the favaorite groups shown in the browser, add them under the *[favorite-groups]* section
in "~/.pyscmpd/pyscmp.conf". The format used for favorite users is:
- groups: group1, group2, ...
+ categroy1: group1, group2, ...
+ categroy2: group1, group2, ...
+ ...
-*groupN* is shon in the broser as subfolder of the *favorite-groups* folder. *groupN* is the group name as shown
+*categoryN* is shown in the broser as subfolder of the *groups* folder. *groupN* is the group name as shown
in the URL when browsing a group. E.g. "deep-house-4".
__Favorite Favorites__
-To define a set of users whos favorite tracks are listed under the *favorite-favorites* folder, add them to the
+To define a set of users whos favorite tracks are listed under the *favorites* folder, add them to the
*[favorite-favorites]* section in "~/.pyscmpd/pyscmp.conf". The format used for favorite favorites is:
- favorites: <user1>, <user2>, ...
+ category1: user1, user2, ...
+ category2: user1, user2, ...
+ ...
-For each *userN*, a subfolder of *favorite-favorites* is shown in the browser. When *userN* is opened, all the favorite
-tracks of that user are listed.
+For each *categoryN*, a subfolder of *favorites* is shown in the browser. When *userN* is opened, all the favorite tracks of that user are listed.
__Complete Example__
@@ -252,10 +257,12 @@ The following shows a complete sample for the two mentioned section as seen in *
tech-house: beatkind, atmosphererecords
[favorite-groups]
- groups: deep-house-4, minimal-tech-house, swing-fever-electroswing-group, ghettoswing-and-swingstep
+ house: deep-house-4, minimal-tech-house,
+ swing: swing-fever-electroswing-group, ghettoswing-and-swingstep
[favorite-favorites]
- favorites: kaltpost
+ me: kaltpost
+ friends: somefrinduser
__Note:__ Each time "~/.pyscmpd/pyscmp.conf" is modified, the daemon needs to be restarted by:
View
11 etc/pyscmpd.conf
@@ -28,8 +28,7 @@ file=/tmp/pyscmpd.log
##
[favorite-users]
-electroswing : shemian
-gethoswing : maddecent, barelylegit
+electroswing : shemian, maddecent, barelylegit
electrosoul : griz
deephouse : freudeamtanzen, adriatique
worldtrance : gogmusic
@@ -37,18 +36,18 @@ worldtrance : gogmusic
##
# Favorite groups
#
-# format: groups: <group1>, <group2>, ...
+# format: <category>: <user1>, <user2>, ...
##
[favorite-groups]
-groups: deep-house-4, minimal-tech-house
+house: deep-house-4, minimal-tech-house
##
# Favorite favorites
#
-# format: favorites: <user1>, <user2>, ...
+# format: <category>: <user1>, <user2>, ...
##
[favorite-favorites]
-favorites: kaltpost
+me: kaltpost
View
28 src/pyscmpd/daemon.py
@@ -237,21 +237,29 @@ def readConfig(self, cfgFile, foreground=False):
self.favoriteUsers.append({"name" : category.strip(), "users" : users})
- if parser.has_option("favorite-groups", "groups"):
+ if parser.has_section("favorite-groups"):
- groupsRaw = parser.get("favorite-groups", "groups").split(",")
- groups = []
+ for category, values in parser.items("favorite-groups"):
- for group in groupsRaw:
- self.favoriteGroups.append(group.strip())
+ groupsRaw = values.split(",")
+ groups = []
- if parser.has_option("favorite-favorites", "favorites"):
+ for group in groupsRaw:
+ groups.append(group.strip())
+
+ self.favoriteGroups.append({"name" : category.strip(), "groups" : groups})
+
+ if parser.has_section("favorite-favorites"):
- favoritesRaw = parser.get("favorite-favorites", "favorites").split(",")
- favorites = []
+ for category, values in parser.items("favorite-favorites"):
+
+ favoritesRaw = values.split(",")
+ favorites = []
+
+ for favorite in favoritesRaw:
+ favorites.append(favorite.strip())
- for favorite in favoritesRaw:
- self.favoriteFavorites.append(favorite.strip())
+ self.favoriteFavorites.append({"name" : category.strip(), "users" : favorites})
except Exception as e:
View
12 src/pyscmpd/gstplayer.py
@@ -81,7 +81,7 @@ def play(self, filePos=0):
f = self.children[filePos]
- logging.info("Playing file at playlist pos %d: %s" % (filePos, f.__str__()))
+ logging.info("Playing file at playlist pos %d: %s" % (filePos, f.getName()))
self.player.set_state(gst.STATE_NULL)
self.player.set_property('uri', f.getStreamUri())
@@ -171,7 +171,7 @@ def getResourcePosInPlaylist(self, res, playlist):
def move(self, filePosFrom, filePosTo):
- logging.info("move posFrom %d, posTo %d" % (filePosFrom, filePosTo))
+ logging.debug("Move posFrom %d, posTo %d" % (filePosFrom, filePosTo))
if filePosFrom > len(self.children):
logging.error("Invalid filePosFrom (%d) given. Only %d files in current playlist." %
@@ -188,7 +188,7 @@ def move(self, filePosFrom, filePosTo):
c = children[filePosFrom]
- logging.info("File on posFrom: %s" % c.__str__())
+ logging.debug("File on posFrom: %s" % c.__str__())
children.remove(c)
children.insert(filePosTo, c)
@@ -206,7 +206,7 @@ def moveId(self, fileIdFrom, filePosTo):
if fileIdFrom <= resource.ID_OFFSET:
- logging.info("using moveId/move mixup workaround")
+ logging.debug("Using moveId/move mixup workaround")
# I think client is doing wrong and mixes up moveId with move
# (ncmpcpp does this). Anyway, trying to workaorund this ...
@@ -214,7 +214,7 @@ def moveId(self, fileIdFrom, filePosTo):
else:
- logging.info("moveId idFrom %d, posTo %d" % (fileIdFrom, filePosTo))
+ logging.debug("moveId idFrom %d, posTo %d" % (fileIdFrom, filePosTo))
if filePosTo > len(self.children):
logging.error("Invalid filePosTo (%d) given. Only %d files in current playlist." %
@@ -340,7 +340,7 @@ def listPlaylists(self):
try:
for (root, dirs, files) in os.walk(PLAYLIST_DIR):
- logging.info("found playlist files: %s" % files)
+ logging.debug("Found playlist files: %s" % files)
for f in files:
plFiles.append(f)
View
6 src/pyscmpd/pyscmpdctrl.py
@@ -51,12 +51,12 @@ def prepare():
f.write("level=info\n")
f.write("file=%s\n" % DEF_LOG_FILE)
f.write("\n[favorite-users]\n")
- f.write("gethoswing : maddecent, barelylegit\n")
+ f.write("electroswing : maddecent, barelylegit\n")
f.write("electrosoul: griz\n")
f.write("\n[favorite-groups]\n")
- f.write("groups: deep-house-4, minimal-tech-house\n")
+ f.write("house: deep-house-4, minimal-tech-house\n")
f.write("\n[favorite-favorites]\n")
- f.write("favorites: kaltpost\n")
+ f.write("me: kaltpost\n")
f.close()
pyscmpd = None
View
2 src/pyscmpd/resource.py
@@ -120,7 +120,7 @@ def getChildByPath(self, path):
while True:
(l, s, r) = p.partition("/")
- logging.info("Consuming path [%s]/[%s]" % (l, r))
+ logging.debug("Consuming path [%s]/[%s]" % (l, r))
if l == "" or c == None or not c.getType() == Resource.TYPE_DIRECTORY:
return None
View
4 src/pyscmpd/scmpd.py
@@ -210,7 +210,7 @@ def songs(self):
l = len(p)
for t in p:
- logging.info("Track: %s" % t.__str__())
+ logging.debug("Track: %s" % t.__str__())
s = mpdserver.MpdPlaylistSong(
playlistPosition = i,
artist = t.getMeta("Artist").encode('ASCII', 'ignore'),
@@ -260,7 +260,7 @@ def handle_args(self, song):
self.uniqueId = t.getId()
- logging.info("Successfully added song: %s" % t.__str__())
+ logging.debug("Successfully added song: %s" % t.__str__())
def items(self):
return [("id", self.uniqueId)]
View
183 src/pyscmpd/scprovider.py
@@ -49,9 +49,7 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
resource.DirectoryResource.__init__(self, 0, "pyscmpd", "pyscmpd")
- # uall = Users("random-users")
-
- ufavgrp = "favorite-users"
+ ufavgrp = "users"
ufav = resource.DirectoryResource(0, ufavgrp, ufavgrp)
ufav.setMeta({"directory" : ufavgrp})
@@ -59,83 +57,36 @@ def __init__(self, favoriteUsers, favoriteGroups, favoriteFavorites):
f = FavoriteUsers(fav["name"], fav["users"], ufavgrp)
ufav.addChild(f)
- # grps = Groups("random-groups")
-
- gfavgrp = "favorite-groups"
+ gfavgrp = "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)
+ f = FavoriteGroups(fav["name"], fav["groups"], gfavgrp)
gfav.addChild(f)
- ffavgrp = "favorite-favorites"
+ ffavgrp = "favorites"
ffav = resource.DirectoryResource(0, ffavgrp, ffavgrp)
ffav.setMeta({"directory" : ffavgrp})
for fav in favoriteFavorites:
- u = User(0, "/users/" + fav + "/favorites", fav, fav, ffavgrp)
- u.setMeta({"directory" : ffavgrp + "/" + fav})
- ffav.addChild(u)
-
- self.addChild(ufav)
- # self.addChild(uall)
- # self.addChild(grps)
- self.addChild(gfav)
- self.addChild(ffav)
-
-'''
-class Users(resource.DirectoryResource):
-
- retriveLock = None
-
- def __init__(self, category):
-
- resource.DirectoryResource.__init__(self, 0, category, category)
-
- self.setMeta({"directory" : 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:
+
+ logging.info("Adding new favorites folder [%s] with favorites [%s]" %
+ (fav["name"], fav["users"]))
- u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink,
- user.username, self.name)
- u.setMeta({"directory" : self.name + "/" + user.permalink})
+ d = resource.DirectoryResource(0, ffavgrp + "/" + fav["name"], fav["name"])
+ d.setMeta({"directory" : ffavgrp + "/" + fav["name"]})
- self.addChild(u)
+ for user in fav["users"]:
+ u = User(0, "/users/" + user + "/favorites", user, user, ffavgrp + "/" + fav["name"])
+ u.setMeta({"directory" : ffavgrp + "/" + fav["name"] + "/" + user})
+ d.addChild(u)
- logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
- (user.uri, u.getId(), user.permalink))
+ ffav.addChild(d)
- except Exception as e:
- logging.warn("Unable to retrive data for URI %s: %s" % (uri, `e`))
-
- except Exception as e:
- logging.warn("Unable to retrive data for URI users: %s" % `e`)
-'''
+ self.addChild(ufav)
+ self.addChild(gfav)
+ self.addChild(ffav)
class FavoriteUsers(resource.DirectoryResource):
@@ -171,11 +122,11 @@ def retriveChildren(self):
self.children = []
- for uri in self.users:
+ for uname in self.users:
try:
- user = ResourceProvider.sc.get("/users/" + uri)
+ user = ResourceProvider.sc.get("/users/" + uname)
u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink, user.username,
self.category + "/" + self.name)
@@ -183,23 +134,29 @@ def retriveChildren(self):
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))
+
+ 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" % (uri, `e`))
+ logging.warn("Unable to retrive data for URI %s: %s" % (uname, `e`))
-class FavoriteGroup(resource.DirectoryResource):
+class FavoriteGroups(resource.DirectoryResource):
retriveLock = None
+ groups = None
category = None
- def __init__(self, name, category):
+ 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})
@@ -219,72 +176,27 @@ 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 + "/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`)
-
-'''
-class Groups(resource.DirectoryResource):
-
- retriveLock = None
- category = None
-
- def __init__(self, category):
-
- resource.DirectoryResource.__init__(self, 0, category, category)
-
- self.category = category
- self.children = None
- self.retriveLock = Lock()
-
- self.setMeta({"directory" : self.category})
-
- def getAllChildren(self):
-
- self.retriveLock.acquire()
+ for gname in self.groups:
- if self.children == None:
- self.retriveChildren()
-
- self.retriveLock.release()
+ try:
- return self.children
-
- def retriveChildren(self):
+ group = ResourceProvider.sc.get("/resolve", url="http://soundcloud.com/groups/%s" %
+ self.name)
- self.children = []
+ users = ResourceProvider.sc.get("/groups/%d/users" % group.id)
- try:
-
- groups = ResourceProvider.sc.get("/groups")
+ for user in users:
+ u = User(resource.ID_OFFSET + user.id, user.uri + "/tracks", user.permalink,
+ user.username, self.category + "/" + self.name)
- for group in groups:
- logging.info("processing group %s" % group.permalink)
- g = Group(resource.ID_OFFSET + group.id, group.permalink, self.category)
- g.setMeta({"directory" : self.category + "/" + group.permalink})
- self.addChild(g)
+ u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
+ self.addChild(u)
- logging.info("successfully retrieved data for URI %s: id=%d; name=%s" %
- (group.uri, g.getId(), group.permalink))
+ 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`)
-'''
+ except Exception as e:
+ logging.warn("Unable to retrive data for groups: %s" % `e`)
class Group(resource.DirectoryResource):
@@ -329,7 +241,7 @@ def retriveChildren(self):
u.setMeta({"directory" : self.category + "/" + self.name + "/" + user.permalink})
self.addChild(u)
- logging.info("successfully retrieved user data: id=%d; name=%s" %
+ logging.info("Successfully retrieved user data: id=%d; name=%s" %
(u.getId(), user.permalink))
except Exception as e:
@@ -368,7 +280,6 @@ def retriveChildren(self):
try:
- logging.info("Trying to get tracks for user [%s] with uri [%s]" % (self.name, self.location))
tracks = ResourceProvider.sc.get(self.location)
for track in tracks:
@@ -381,13 +292,13 @@ def retriveChildren(self):
self.addChild(tr)
- logging.info("Added track to user [%s]: %s" % (self.getName(), tr.__str__()))
+ 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(self.children), self.getName()))
class Track(resource.FileResource):

0 comments on commit 53b0de8

Please sign in to comment.
Something went wrong with that request. Please try again.