def save(self, filename): self.log("save " + filename) try: fle = FileAccess.open(filename, 'w') except: self.log("save Unable to open the smart playlist", xbmc.LOGERROR) return flewrite = uni("#EXTM3U\n") for i in range(self.size()): tmpstr = str(self.getduration(i)) + ',' tmpstr += self.getTitle(i) + "//" + self.getepisodetitle( i) + "//" + self.getdescription(i) tmpstr = uni(tmpstr[:2036]) tmpstr = tmpstr.replace("\\n", " ").replace("\\r", " ").replace("\\\"", "\"") tmpstr = tmpstr + '\n' + self.getfilename(i) flewrite += "#EXTINF:" + tmpstr + "\n" fle.write(flewrite) fle.close()
def load(self, filename): self.log("load " + filename) self.processingSemaphore.acquire() self.clear() try: fle = FileAccess.open(filename, 'r') except IOError: self.log('Unable to open the file: ' + filename) self.processingSemaphore.release() return False # find and read the header try: lines = fle.readlines() except: self.log("ERROR loading playlist: " + filename) self.log(traceback.format_exc(), xbmc.LOGERROR) fle.close() realindex = -1 for i in range(len(lines)): if lines[i].startswith('#EXTM3U'): realindex = i break if realindex == -1: self.log('Unable to find playlist header for the file: ' + filename) self.processingSemaphore.release() return False # past the header, so get the info for i in range(len(lines)): if realindex + 1 >= len(lines): break if len(self.itemlist) > 16384: break try: line = uni(lines[realindex].rstrip()) except: self.log("ERROR: Invalid line in playlist - " + filename) self.log(traceback.format_exc(), xbmc.LOGERROR) if line[:8] == '#EXTINF:': tmpitem = PlaylistItem() index = line.find(',') if index > 0: tmpitem.duration = int(line[8:index]) tmpitem.title = line[index + 1:] index = tmpitem.title.find('//') if index >= 0: tmpitem.episodetitle = tmpitem.title[index + 2:] tmpitem.title = tmpitem.title[:index] index = tmpitem.episodetitle.find('//') if index >= 0: tmpitem.description = tmpitem.episodetitle[index + 2:] tmpitem.episodetitle = tmpitem.episodetitle[:index] index = tmpitem.description.find( '//' ) #closing off description now that there are parameters beyond it if index >= 0: #we don't actually need playcount (or resume) here but this is how we close off description tmpitem.playcount = tmpitem.description[index + 2:] tmpitem.description = tmpitem.description[: index] realindex += 1 tmpitem.filename = uni(lines[realindex].rstrip()) self.itemlist.append(tmpitem) self.totalDuration += tmpitem.duration realindex += 1 self.processingSemaphore.release() if len(self.itemlist) == 0: return False return True