annotate light9/wavelength.py @ 680:ad17b0a09f5c

CC more startup logging, timing option to quit after init Ignore-this: 6116d151a3c36a7830740a7407d5665c
author drewp@bigasterisk.com
date Tue, 21 Jun 2011 01:58:49 +0000
parents a6f4a5b2647c
children f066d6e874db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
243
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
1 #!/usr/bin/python
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
2
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
3 from __future__ import division, nested_scopes
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
4 import sys, wave
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
5
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
6 def wavelength(filename):
433
a6f4a5b2647c convert music to ogg, since mpd seeking in .wav is broken this year
drewp@bigasterisk.com
parents: 243
diff changeset
7 filename = filename.replace('.ogg', '.wav')
243
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
8 wavefile = wave.open(filename, 'rb')
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
9
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
10 framerate = wavefile.getframerate() # frames / second
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
11 nframes = wavefile.getnframes() # number of frames
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
12 song_length = nframes / framerate
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
13
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
14 return song_length
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
15
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
16 if __name__ == "__main__":
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
17 for songfile in sys.argv[1:]:
fff8762db48a finished incomplete patch- asco now measures the length of songs (only for .wav)
drewp@bigasterisk.com
parents:
diff changeset
18 print songfile, wavelength(songfile)