forked from beetbox/pyacoustid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpcalc.py
executable file
·65 lines (54 loc) · 2.2 KB
/
fpcalc.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
#!/usr/bin/env python
# This file is part of pyacoustid.
# Copyright 2012, Lukas Lalinsky.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
"""Simple script for calculating audio fingerprints, using the same
arguments/output as the fpcalc utility from Chromaprint."""
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
import argparse
import sys
import acoustid
import chromaprint
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-length', metavar='SECS', type=int, default=120,
help='length of the audio data used for fingerprint '
'calculation (default 120)')
parser.add_argument('-raw', action='store_true',
help='output the raw uncompressed fingerprint')
parser.add_argument('paths', metavar='FILE', nargs='+',
help='audio file to be fingerprinted')
args = parser.parse_args()
# make gst not try to parse the args
del sys.argv[1:]
first = True
for i, path in enumerate(args.paths):
try:
duration, fp = acoustid.fingerprint_file(path, args.length)
except Exception:
print("ERROR: unable to calculate fingerprint "
"for file %s, skipping" % path, file=sys.stderr)
continue
if args.raw:
raw_fp = chromaprint.decode_fingerprint(fp)[0]
fp = ','.join(map(str, raw_fp))
if not first:
print
first = False
print('FILE=%s' % path)
print('DURATION=%d' % duration)
print('FINGERPRINT=%s' % fp.decode('utf8'))
if __name__ == '__main__':
main()