forked from asermax/lastfm_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatcher.py
executable file
·44 lines (36 loc) · 1.23 KB
/
matcher.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
#!/usr/bin/env python
"""A simple program for using pylastfp to fingerprint MP3 files. Usage:
$ python matcher.py mysterious_music.mp3
"""
import sys, os, lastfp
import LastFMExtensionKeys as Keys
'''
Modified match function to return only the fpid
'''
def match(apikey, pcmiter, samplerate, duration, channels=2, metadata=None):
fpdata = lastfp.extract(pcmiter, samplerate, channels)
fpid = lastfp.fpid_query(duration, fpdata, metadata)
return fpid
lastfp.match = match
if __name__ == '__main__':
args = sys.argv[1:]
if not args:
print "usage: matcher.py mysterious_music.mp3"
sys.exit(1)
path = os.path.abspath(os.path.expanduser(args[0]))
artist = args[1]
album = args[2]
title = args[3]
# Perform match.
try:
fpid = lastfp.match_file(Keys.API_KEY, path, metadata={ 'artist':artist,
'album':album,
'track':title })
except lastfp.ExtractionError:
print 'Fingerprinting failed! (Is the song too short?)'
sys.exit(1)
except lastfp.QueryError:
print 'Could not match fingerprint!'
sys.exit(1)
# Show fpid
print fpid