#!/usr/bin/python # apt-get install python-mutagen import os import os.path import mutagen MUSICDIR="/store/musica" TARGET=os.path.expanduser("~/.zavai/player-info") # Ensure there's a / in the end, which makes it easier to strip the prefix # later if MUSICDIR[-1] != '/': MUSICDIR += '/' def names(): for root, dirs, files in os.walk(MUSICDIR): for name in (f for f in files if f.endswith(".mp3")): fname = os.path.join(root, name) mf = mutagen.File(fname) # Scan fname somehow yield dict(name=fname, length=mf.info.length) out = open(TARGET, "w") pfxlen = len(MUSICDIR) for info in sorted(names(), key=lambda x:x["name"]): name = info["name"][pfxlen:] print >>out, "file:", name print >>out, "length:", int(round(info["length"] * 1000)) print >>out out.close()