changeset 15:ae3451bedeb6

Implemented playlist searching
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Sat, 19 Aug 2006 23:53:56 -0400
parents 2ca1ce7cb338
children 447b47ab396f
files vixm/playlist.py vixm/song.py vixm/ui.py
diffstat 3 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/vixm/playlist.py	Sat Aug 19 20:23:52 2006 -0400
+++ b/vixm/playlist.py	Sat Aug 19 23:53:56 2006 -0400
@@ -1,6 +1,6 @@
 # a playlist definition
 
-import xmms
+import xmms, re
 
 LIST_PRIO	= 0
 LIST_DEFAULT	= 1
@@ -30,6 +30,12 @@
 		""" Return the length of the playlist """
 		return len(self.__list)
 
+	def search(self, regexp):
+		""" Yield all the songs matching regexp """
+		for song in self.__list:
+			if re.search(regexp, str(song), re.IGNORECASE):
+				yield song
+
 	def index(self, song):
 		""" Returns the index of the first occurence of song """
 		return self.__list.index(song)
--- a/vixm/song.py	Sat Aug 19 20:23:52 2006 -0400
+++ b/vixm/song.py	Sat Aug 19 23:53:56 2006 -0400
@@ -7,3 +7,5 @@
 		self["pos"]	= pos
 		self["title"]	= xmms.control.get_playlist_title(pos)
 
+	def __str__(self):
+		return self["title"]
--- a/vixm/ui.py	Sat Aug 19 20:23:52 2006 -0400
+++ b/vixm/ui.py	Sat Aug 19 23:53:56 2006 -0400
@@ -204,13 +204,20 @@
 		
 		print "Invalid command \"%s\"" % (txt,)
 
+	def search(self, lid, regexp):
+		print "Seaching list %d for '%s':" % (lid, regexp)
+		for song in self.lists[lid].search(regexp):
+			idx = self.lists[lid].index(song)+1
+			print "%d. %s" % (idx, str(song))
+
 	def run(self):
 		while not self.shutdown:
 			tmp = sys.stdin.readline().strip()
 			
 			if tmp.startswith("/"):
 				# '/ABC' - searching
-				print "Searching not yet implemented"
+				self.search(playlist.LIST_PRIO, tmp[1:])
+				self.search(playlist.LIST_DEFAULT, tmp[1:])
 			else:
 				# 'ABC' - commands
 				self.__cmd(tmp)