/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. import sys
  4. import os
  5. import eyeD3
  6. import tempo
  7. def show_tempo(mp3):
  8. "given an mp3, print out the artist, title and tempo of the song"
  9. tag = eyeD3.Tag()
  10. tag.link(mp3)
  11. my_tempo = tempo.get_tempo(tag.getArtist(), tag.getTitle())
  12. print 'File: ', mp3
  13. print 'Artist:', tag.getArtist()
  14. print 'Title: ', tag.getTitle()
  15. print 'Tempo: ', my_tempo
  16. print
  17. def show_tempos(dir):
  18. "print out the tempo for each MP3 in the give directory"
  19. for f in os.listdir(dir):
  20. if f.lower().endswith(".mp3"):
  21. path = os.path.join(dir, f)
  22. show_tempo(path)
  23. if __name__ == '__main__':
  24. if len(sys.argv) == 1:
  25. print 'usage: python show_tempos.py path'
  26. else:
  27. show_tempos(sys.argv[1])