#! /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()