fix position of movie length
[enigma2.git] / lib / python / Components / Playlist.py
index 704b2f84bf73bbd1dc2ac2f7b4897adc4b0437f9..2279969275f0117bb882c222d226db92ebb6ecc0 100644 (file)
@@ -1,4 +1,5 @@
 from ServiceReference import ServiceReference
+import os
 
 class PlaylistIO:      
        def __init__(self):
@@ -49,4 +50,63 @@ class PlaylistIOInternal(PlaylistIO):
                        file.write(str(x) + "\n")
                file.close()
                
-               return self.OK
\ No newline at end of file
+               return self.OK
+       
+class PlaylistIOM3U(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
+                       if entry[0] != "#":
+                               # TODO: use e2 facilities to create a service ref from file
+                               if entry[0] == "/":
+                                       self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + entry))
+                               else:
+                                       self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + os.path.dirname(filename) + "/" + entry))
+               file.close()
+               return self.list
+               
+       def save(self, filename = None):
+               return self.ERROR
+       
+class PlaylistIOPLS(PlaylistIO):
+       def __init__(self):
+               PlaylistIO.__init__(self)
+       
+       def open(self, filename):
+               self.clear()
+               try:
+                       file = open(filename, "r")
+               except IOError:
+                       return None
+               entry = file.readline().strip()
+               if entry == "[playlist]": # extended pls
+                       while True:
+                               entry = file.readline().strip()
+                               if entry == "":
+                                       break
+                               if entry[0:4] == "File":
+                                       pos = entry.find('=') + 1
+                                       newentry = entry[pos:]
+                                       # TODO: use e2 facilities to create a service ref from file
+                                       if newentry[0] == "/":
+                                               self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + newentry))
+                                       else:
+                                               self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + os.path.dirname(filename) + "/" + newentry))
+               else:
+                       playlist = PlaylistIOM3U()
+                       return playlist.open(filename)
+               file.close()
+               return self.list
+               
+       def save(self, filename = None):
+               return self.ERROR
\ No newline at end of file