BlinkenArea - GitList
Repositories
Blog
Wiki
stage_director
Code
Commits
Branches
Tags
Search
Tree:
6d1a6cb
Branches
Tags
master
stage_director
playlist.py
comments by ST
Stefan Schuermans
commited
6d1a6cb
at 2013-11-24 16:12:00
playlist.py
Blame
History
Raw
#! /usr/bin/env python # BlinkenArea Stage Director # Copyright 2013 Stefan Schuermans <stefan@blinkenarea.org> # Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html # a blinkenarea.org project - https://www.blinkenarea.org/ import re import pango import time_fmt class Playlist: """ playlist object, reads a playlist form a file and handles the playlist entries playlist file format: - each line is an entry or a stop point: <line> = <entry> | <stop point> - entries are played one after another - playing halts at stop points - <entry> = <name> <whitespace> <duration> - <stop point> = "" - <name> = [A-Za-Z0-9_]+ - <duration> = ((<hours>:)?<minutes>:)?<seconds> - <hours> = [0-9]+ - <minutes> = [0-9]+ - <seconds> = [0-9]+(.[0-9]+)""" def __init__(self): """create a new, empty playlist object""" self.entries = [] # list of entries # entry = dictionary { "type": "normal" or "stop" # "name": string, name of entry # "durtaion": float, in seconds } self.reEntry = re.compile("^\s*([A-Za-z0-9_]+)\s+([0-9:.]+)\s*$") def read(self, filename): """read the playlist from filename, replacing the current playlist""" 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("DEBUG playlist entry normal %s %f" % # (self.entries[-1]["name"], self.entries[-1]["duration"])) else: self.entries.append({"type": "stop"}) #print("DEBUG playlist entry stop") f.close() def update(self, store): """update the contents of a Gtk ListStore with the contents of this playlist""" store.clear() idx = 0 for entry in self.entries: if entry["type"] == "normal": name = entry["name"] duration = time_fmt.sec2str(entry["duration"]) else: name = "" duration = "STOP" store.append([idx, pango.WEIGHT_NORMAL, name, duration]) idx = idx + 1