X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/f44dfc20f4ed708d67603f767a976c1168393627..c8cb4ee317b6f85d3646a7718887581c36f49291:/lib/python/Components/Playlist.py diff --git a/lib/python/Components/Playlist.py b/lib/python/Components/Playlist.py index 704b2f84..22799692 100644 --- a/lib/python/Components/Playlist.py +++ b/lib/python/Components/Playlist.py @@ -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