-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3stats.py
executable file
·72 lines (55 loc) · 1.52 KB
/
mp3stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
from accordion import *
import sys
import string
import os
import pickle
import fnmatch
def strip_newline(data):
# find new line and strip everything before it
for i in range(0,len(data)):
if data[i] == '\n':
return data[i+1:]
# oops, didn't find anything offending
return data
versions = {0x0200:[], 0x0300:[], 0x0400:[], "unknown":[]}
frames = {}
errors = []
def do_id3(filename):
try:
id3 = ID3v2(filename, ID3V2_FILE_READ)
if versions.has_key(id3.tag["version"]):
versions[id3.tag["version"]].append(filename)
else:
versions["unknown"].append(filename)
for f in id3.frames:
if frames.has_key(f.fid):
frames[f.fid].append(filename)
else:
frames[f.fid] = [filename]
except ID3Exception:
print "Unable to find ID3v2 Tag"
errors.append((filename,"unable to find id3v2 tag"))
def do_recurse(filename):
if os.path.isdir(filename):
print "traversing dir:", filename
for f in fnmatch.filter(os.listdir(filename), '*.mp3'):
do_recurse(os.path.join(filename, f))
else:
print "checking file:", filename
do_id3(filename)
for filename in sys.argv[1:]:
do_recurse(filename)
# dump stats:
#pickle.dump(versions,open("stats.versions",'wb'))
#pickle.dump(frames,open("stats.frames",'wb'))
#pickle.dump(errors,open("stats.errors",'wb'))
print "Version Distributions:"
for k,v in versions.items():
print k, len(v)
print "Frames Used:"
for k,v in frames.items():
print k, len(v)
print "Errors:"
for e in errors:
print e[0], ":", e[1]