annotate light9/wavelength.py @ 1336:2d77dc9436c3

music drives cursor Ignore-this: ffa7a9a94084bb8feab6d04e888fb3f6
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 04 Jun 2016 21:23:58 +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)