3 # apt-get install python-mutagen
9 MUSICDIR="/store/musica"
10 TARGET=os.path.expanduser("~/.zavai/player-info")
12 # Ensure there's a / in the end, which makes it easier to strip the prefix
14 if MUSICDIR[-1] != '/':
18 for root, dirs, files in os.walk(MUSICDIR):
19 for name in (f for f in files if f.endswith(".mp3")):
20 fname = os.path.join(root, name)
21 mf = mutagen.File(fname)
23 yield dict(name=fname, length=mf.info.length)
25 out = open(TARGET, "w")
26 pfxlen = len(MUSICDIR)
27 for info in sorted(names(), key=lambda x:x["name"]):
28 name = info["name"][pfxlen:]
29 print >>out, "file:", name
30 print >>out, "length:", int(round(info["length"] * 1000))