1 from ServiceReference import ServiceReference
2 from enigma import eServiceReference
9 # returns a list of services or None if filename is not a valid playlist
10 def open(self, filename):
17 UNSUPPORTED_FILES_IN_PLAYLIST = 4
19 REMOTE_PROTOS = ["http", "https", "udp", "rtsp", "rtp", "mmp"]
21 def save(self, filename = None):
27 def addService(self, service):
28 self.list.append(service)
30 def getRef(self, filename, entry):
34 path = os.path.dirname(filename) + "/" + entry
35 for proto in self.REMOTE_PROTOS:
36 if entry.startswith(proto):
38 ref = eServiceReference(4097, 0, path)
39 return ServiceReference(ref)
41 class PlaylistIOInternal(PlaylistIO):
43 PlaylistIO.__init__(self)
45 def open(self, filename):
48 file = open(filename, "r")
52 entry = file.readline().strip()
55 self.addService(ServiceReference(entry))
59 def save(self, filename = None):
60 print "Writing playlist into file", filename
61 file = open(filename, "w")
63 file.write(str(x) + "\n")
68 class PlaylistIOM3U(PlaylistIO):
70 PlaylistIO.__init__(self)
72 def open(self, filename):
74 self.displayname = None
76 file = open(filename, "r")
80 entry = file.readline().strip()
83 if entry.startswith("#EXTINF:"):
84 extinf = entry.split(',',1)
86 self.displayname = extinf[1]
87 # TODO: use e2 facilities to create a service ref from file
89 sref = PlaylistIO.getRef(self, filename, entry)
91 sref.ref.setName(self.displayname)
92 self.displayname = None
97 def save(self, filename = None):
100 class PlaylistIOPLS(PlaylistIO):
102 PlaylistIO.__init__(self)
104 def open(self, filename):
107 file = open(filename, "r")
110 entry = file.readline().strip()
111 if entry == "[playlist]": # extended pls
113 entry = file.readline().strip()
116 if entry[0:4] == "File":
117 pos = entry.find('=') + 1
118 newentry = entry[pos:]
119 sref = PlaylistIO.getRef(self, filename, newentry)
120 self.addService(sref)
122 playlist = PlaylistIOM3U()
123 return playlist.open(filename)
127 def save(self, filename = None):