-
Notifications
You must be signed in to change notification settings - Fork 2
/
submit_echoprints.py
executable file
·63 lines (52 loc) · 1.67 KB
/
submit_echoprints.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
#!/usr/bin/python
import sys
import os
import tag
from musicbrainz import musicbrainz
import echonest
import conf
musicbrainz.auth(conf.mb_user, conf.mb_pass)
musicbrainz.hostname = "echoprint.musicbrainz.org"
def submit_dir(directory):
if not os.path.isdir(directory):
print "Skipping (not a direcory):", directory
print "Processing directory", directory
files = os.listdir(directory)
metadata = {}
for f in sorted(files):
filename = os.path.join(directory, f)
if os.path.splitext(filename)[1] in tag.supported_extensions:
metadata.update(get_metadata(filename))
if len(metadata):
print "Submitting...",
try:
resp = musicbrainz.submit_echoprints(metadata)
except musicbrainz.urllib2.HTTPError:
print "Auth failed. Is your password 'mb'?"
return
if resp["message"]["text"] == "OK":
print "done"
else:
print "Error submitting:", resp["message"]["text"]
else:
print "No files found"
def get_metadata(filename):
print os.path.basename(filename)
try:
trackid = tag.read_tags(filename)['MUSICBRAINZ_TRACKID']
except:
print " Track has no tagged musicbrainz track id"
return {}
echoprint = echonest.fingerprint(filename)
if echoprint:
print " %s:%s" % (trackid, echoprint)
return {trackid:echoprint}
else:
print " Not found in echoprint"
return {}
if __name__ == "__main__":
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: %s [directories ...]" % sys.argv[0]
sys.exit(1)
for d in sys.argv[1:]:
submit_dir(d)