# HG changeset patch # User drewp@bigasterisk.com # Date 2005-06-14 02:52:37 # Node ID fff8762db48a5759151d91adaad6e34d7a6f7b2d # Parent 561b4202461dc0c3a2c7d80dfd41a18c7658dc7c finished incomplete patch- asco now measures the length of songs (only for .wav) diff --git a/bin/ascoltami b/bin/ascoltami --- a/bin/ascoltami +++ b/bin/ascoltami @@ -29,7 +29,7 @@ from twisted.internet.error import Canno from twisted.web import xmlrpc, server import run_local -from light9 import networking, showconfig +from light9 import networking, showconfig, wavelength from pympd import Mpd @@ -138,7 +138,9 @@ class Player: reactor.callLater(.05, self.pollStatus) def set_total_time(self, song_path): - raise NotImplementedError("get lengther.py from semprini") + # currently only good for .wav + p = os.path.join(showconfig.musicDir(), song_path) + self.total_time.set(wavelength.wavelength(p)) def play(self, song_path): @@ -150,13 +152,6 @@ class Player: self.filename_var.set(song_path) self.set_total_time(song_path) -## # jump to song 1 to get its total_time -## self.mpd.seek(seconds=0, song=1) -## self.mpd.pause() -## self.mpd.status().addCallback(self.play2) - -## def play2(self, stat): -## self.total_time.set(stat.time_total) self.mpd.seek(seconds=0, song=0) def check_autopause(self): diff --git a/light9/wavelength.py b/light9/wavelength.py new file mode 100644 --- /dev/null +++ b/light9/wavelength.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +from __future__ import division, nested_scopes +import sys, wave + +def wavelength(filename): + wavefile = wave.open(filename, 'rb') + + framerate = wavefile.getframerate() # frames / second + nframes = wavefile.getnframes() # number of frames + song_length = nframes / framerate + + return song_length + +if __name__ == "__main__": + for songfile in sys.argv[1:]: + print songfile, wavelength(songfile)