6e98624edccf0449b87c99c6cfc822585982f195
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

1) #! /usr/bin/env python
2) 
3) import re
4) 
5) import time_fmt
6) 
7) class Playlist:
8)   def __init__(self):
9)     self.entries = []
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

10)     self.reEntry = re.compile("^\s*([A-Za-z0-9_]+)\s+([0-9:.]+)\s*$")
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

11) 
12)   def read(self, filename):
13)     self.entries = []
14)     f = open(filename, "r")
15)     for line in f:
16)       mEntry = self.reEntry.match(line)
17)       if mEntry:
18)         name = mEntry.group(1)
19)         duration = time_fmt.str2sec(mEntry.group(2))
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

20)         self.entries.append({"type":     "normal",
21)                              "name":     name,
22)                              "duration": duration})
23)         print("entry normal %s %f" % (self.entries[-1]["name"],
24)                                       self.entries[-1]["duration"]))
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

25)       else:
Stefan Schuermans show playlist in TreeView

Stefan Schuermans authored 10 years ago

26)         self.entries.append({"type": "stop"})
Stefan Schuermans reading playlist

Stefan Schuermans authored 10 years ago

27)         print("entry stop")
28)     f.close()
29)