Stefan Schuermans commited on 2013-11-14 22:23:33
Showing 4 changed files, with 63 additions and 0 deletions.
... | ... |
@@ -0,0 +1,29 @@ |
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 = [] |
|
10 |
+ self.reEntry = re.compile('^\s*([A-Za-z0-9_]+)\s+([0-9:.]+)\s*$') |
|
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)) |
|
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'])) |
|
25 |
+ else: |
|
26 |
+ self.entries.append({'type': 'stop'}) |
|
27 |
+ print("entry stop") |
|
28 |
+ f.close() |
|
29 |
+ |
... | ... |
@@ -3,6 +3,7 @@ |
3 | 3 |
import os |
4 | 4 |
from gi.repository import Gtk |
5 | 5 |
|
6 |
+import playlist |
|
6 | 7 |
import time_fmt |
7 | 8 |
|
8 | 9 |
scriptdir = os.path.dirname(os.path.abspath(__file__)) |
... | ... |
@@ -30,6 +31,8 @@ class SyncGui: |
30 | 31 |
"onNext": self.onNext, |
31 | 32 |
} |
32 | 33 |
self.builder.connect_signals(handlers) |
34 |
+ self.playlist = playlist.Playlist() |
|
35 |
+ self.playlist.read("playlist.txt") |
|
33 | 36 |
self.status.push(0, "TODO...") |
34 | 37 |
self.showCurrentPosition() |
35 | 38 |
|
... | ... |
@@ -13,4 +13,27 @@ def sec2str(sec): |
13 | 13 |
minu = minu % 60 |
14 | 14 |
return "%s%u:%02u:%02u.%02u" % (sign, hour, minu, sec1, sec100) |
15 | 15 |
|
16 |
+def str2sec(str): |
|
17 |
+ total = 0 |
|
18 |
+ section = 0 |
|
19 |
+ sign = 1 |
|
20 |
+ decimal = 1 |
|
21 |
+ for c in str: |
|
22 |
+ if c == ":": |
|
23 |
+ total = (total + sign * section) * 60 |
|
24 |
+ section = 0 |
|
25 |
+ sign = 1 |
|
26 |
+ decimal = 1 |
|
27 |
+ elif c == "-": |
|
28 |
+ sign = -sign |
|
29 |
+ elif c == ".": |
|
30 |
+ decimal = 0.1 |
|
31 |
+ elif c >= "0" and c <= "9": |
|
32 |
+ if decimal < 1: |
|
33 |
+ section = section + int(c) * decimal |
|
34 |
+ decimal = decimal * 0.1 |
|
35 |
+ else: |
|
36 |
+ section = section * 10 + int(c) |
|
37 |
+ total = total + sign * section |
|
38 |
+ return total |
|
16 | 39 |
|
17 | 40 |