save playlist on leaving the media player
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sat, 17 Jun 2006 20:12:37 +0000 (20:12 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Sat, 17 Jun 2006 20:12:37 +0000 (20:12 +0000)
lib/python/Components/Makefile.am
lib/python/Components/Playlist.py [new file with mode: 0644]
lib/python/Components/__init__.py

index af8d1b9ce7c4150bd5b00baf45f819042b6a9882..560b1ffedd39e97caaae15f5a35084574ccf6f81 100644 (file)
@@ -16,5 +16,5 @@ install_PYTHON = \
        PluginList.py PluginComponent.py RecordingConfig.py About.py UsageConfig.py \
        FIFOList.py ServiceEventTracker.py Input.py TimerSanityCheck.py FileList.py \
        MultiContent.py MediaPlayer.py TunerInfo.py VideoWindow.py ChoiceList.py \
-       Element.py
+       Element.py Playlist.py
 
diff --git a/lib/python/Components/Playlist.py b/lib/python/Components/Playlist.py
new file mode 100644 (file)
index 0000000..704b2f8
--- /dev/null
@@ -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
index 5dd11a82803d2404f67bc4a03aa3568001aec0c5..c303c5a55c24d00cffdd9c21b0e5d826625abc09 100644 (file)
@@ -7,4 +7,4 @@ __all__ = ["ActionMap", "Button", "Clock", "ConfigList", "EventInfo",
        "InputDevice",  "ServicePosition", "IPAddress", "VariableIP", "IPGateway",
        "IPNameserver", "Network", "RFmon", "DiskInfo", "NimManager", "TimerEntry",
        "Lcd", "EpgList" "ScrollLabel", "Timezones", "HelpMenuList", "TimerSanityCheck",
-       "FileList", "MultiContent", "TunerInfo", "ChoiceList" ]
+       "FileList", "MultiContent", "TunerInfo", "ChoiceList", "Playlist" ]