PageRenderTime 342ms CodeModel.GetById 120ms app.highlight 4ms RepoModel.GetById 117ms app.codeStats 0ms

/src/pyechonest/examples/show_tempos.py

http://echo-nest-remix.googlecode.com/
Python | 34 lines | 25 code | 7 blank | 2 comment | 5 complexity | 3332de748fe628d4318dc35a8844d94c MD5 | raw file
 1# Shows the tempos for all of the songs in a director
 2# requires eyeD3, available from http://eyed3.nicfit.net/
 3
 4import sys
 5import os
 6import eyeD3
 7import tempo
 8
 9
10def show_tempo(mp3):
11    "given an mp3, print out the artist, title and tempo of the song"
12    tag = eyeD3.Tag()
13    tag.link(mp3)
14    my_tempo = tempo.get_tempo(tag.getArtist(), tag.getTitle())
15    print 'File:  ', mp3
16    print 'Artist:', tag.getArtist()
17    print 'Title: ', tag.getTitle()
18    print 'Tempo: ', my_tempo
19    print
20
21
22def show_tempos(dir):
23    "print out the tempo for each MP3 in the give directory"
24    for f in os.listdir(dir):
25        if f.lower().endswith(".mp3"):
26            path = os.path.join(dir, f)
27            show_tempo(path)
28
29
30if __name__ == '__main__':
31    if len(sys.argv) == 1:
32        print 'usage: python show_tempos.py path'
33    else:
34        show_tempos(sys.argv[1])