1 from ServiceReference import ServiceReference
8 # returns a list of services or None if filename is not a valid playlist
9 def open(self, filename):
16 UNSUPPORTED_FILES_IN_PLAYLIST = 4
18 def save(self, filename = None):
24 def addService(self, service):
25 self.list.append(service)
28 class PlaylistIOInternal(PlaylistIO):
30 PlaylistIO.__init__(self)
32 def open(self, filename):
35 file = open(filename, "r")
39 entry = file.readline().strip()
42 self.addService(ServiceReference(entry))
46 def save(self, filename = None):
47 print "Writing playlist into file", filename
48 file = open(filename, "w")
50 file.write(str(x) + "\n")
55 class PlaylistIOM3U(PlaylistIO):
57 PlaylistIO.__init__(self)
59 def open(self, filename):
62 file = open(filename, "r")
66 entry = file.readline().strip()
70 # TODO: use e2 facilities to create a service ref from file
72 self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + entry))
74 self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + os.path.dirname(filename) + "/" + entry))
78 def save(self, filename = None):
81 class PlaylistIOPLS(PlaylistIO):
83 PlaylistIO.__init__(self)
85 def open(self, filename):
88 file = open(filename, "r")
91 entry = file.readline().strip()
92 if entry == "[playlist]": # extended pls
94 entry = file.readline().strip()
97 if entry[0:4] == "File":
98 pos = entry.find('=') + 1
99 newentry = entry[pos:]
100 # TODO: use e2 facilities to create a service ref from file
101 if newentry[0] == "/":
102 self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + newentry))
104 self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + os.path.dirname(filename) + "/" + newentry))
106 playlist = PlaylistIOM3U()
107 return playlist.open(filename)
111 def save(self, filename = None):