Started dir with little test programs
[gregoa/zavai.git] / player / zavai-player-update-info
1 #!/usr/bin/python
2
3 # apt-get install python-mutagen
4
5 import os
6 import os.path
7 import mutagen
8
9 MUSICDIR="/store/musica"
10 TARGET=os.path.expanduser("~/.zavai/player-info")
11
12 # Ensure there's a / in the end, which makes it easier to strip the prefix
13 # later
14 if MUSICDIR[-1] != '/':
15     MUSICDIR += '/'
16
17 def names():
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)
22             # Scan fname somehow
23             yield dict(name=fname, length=mf.info.length)
24
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))
31     print >>out
32 out.close()