From f44dfc20f4ed708d67603f767a976c1168393627 Mon Sep 17 00:00:00 2001 From: Stefan Pluecken Date: Sat, 17 Jun 2006 20:12:37 +0000 Subject: save playlist on leaving the media player --- lib/python/Components/Playlist.py | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/python/Components/Playlist.py (limited to 'lib/python/Components/Playlist.py') diff --git a/lib/python/Components/Playlist.py b/lib/python/Components/Playlist.py new file mode 100644 index 00000000..704b2f84 --- /dev/null +++ b/lib/python/Components/Playlist.py @@ -0,0 +1,52 @@ +from ServiceReference import ServiceReference + +class PlaylistIO: + def __init__(self): + self.list = [] + + # returns a list of services or None if filename is not a valid playlist + def open(self, filename): + return None + + OK = 0 + FILEEXISTS = 1 + WRITEERROR = 2 + ERROR = 3 + UNSUPPORTED_FILES_IN_PLAYLIST = 4 + + def save(self, filename = None): + return self.ERROR + + def clear(self): + del self.list[:] + + def addService(self, service): + self.list.append(service) + + +class PlaylistIOInternal(PlaylistIO): + def __init__(self): + PlaylistIO.__init__(self) + + def open(self, filename): + self.clear() + try: + file = open(filename, "r") + except IOError: + return None + while True: + entry = file.readline().strip() + if entry == "": + break + self.addService(ServiceReference(entry)) + file.close() + return self.list + + def save(self, filename = None): + print "Writing playlist into file", filename + file = open(filename, "w") + for x in self.list: + file.write(str(x) + "\n") + file.close() + + return self.OK \ No newline at end of file -- cgit v1.2.3