#! /usr/bin/env python import re import time_fmt class Playlist: def __init__(self): self.entries = [] self.reEntry = re.compile("^\s*([A-Za-z0-9_]+)\s+([0-9:.]+)\s*$") def read(self, filename): self.entries = [] f = open(filename, "r") for line in f: mEntry = self.reEntry.match(line) if mEntry: name = mEntry.group(1) duration = time_fmt.str2sec(mEntry.group(2)) self.entries.append({"type": "normal", "name": name, "duration": duration}) print("entry normal %s %f" % (self.entries[-1]["name"], self.entries[-1]["duration"])) else: self.entries.append({"type": "stop"}) print("entry stop") f.close() def update(self, store): store.clear() for entry in self.entries: if entry["type"] == "normal": name = entry["name"] duration = time_fmt.sec2str(entry["duration"]) else: name = "" duration = "STOP" store.append([name, duration])