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):
61 self.displayname = None
63 file = open(filename, "r")
67 entry = file.readline().strip()
70 if entry.startswith("#EXTINF:"):
71 extinf = entry.split(',',1)
73 self.displayname = extinf[1]
74 # TODO: use e2 facilities to create a service ref from file
77 sref = ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + entry)
78 elif entry.startswith("http"):
79 sref = ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + entry.replace(':',"%3a"))
81 sref = ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + os.path.dirname(filename) + "/" + entry)
83 sref.ref.setName(self.displayname)
84 self.displayname = None
89 def save(self, filename = None):
92 class PlaylistIOPLS(PlaylistIO):
94 PlaylistIO.__init__(self)
96 def open(self, filename):
99 file = open(filename, "r")
102 entry = file.readline().strip()
103 if entry == "[playlist]": # extended pls
105 entry = file.readline().strip()
108 if entry[0:4] == "File":
109 pos = entry.find('=') + 1
110 newentry = entry[pos:]
111 # TODO: use e2 facilities to create a service ref from file
112 if newentry[0] == "/":
113 self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + newentry))
115 self.addService(ServiceReference("4097:0:0:0:0:0:0:0:0:0:" + os.path.dirname(filename) + "/" + newentry))
117 playlist = PlaylistIOM3U()
118 return playlist.open(filename)
122 def save(self, filename = None):