Skip to content

Instantly share code, notes, and snippets.

@MGF15
Last active October 22, 2017 16:51
Show Gist options
  • Save MGF15/71240d6b1461aff19e395ae14ad40229 to your computer and use it in GitHub Desktop.
Save MGF15/71240d6b1461aff19e395ae14ad40229 to your computer and use it in GitHub Desktop.
song finder script
#!/usr/bin/python
import os,urllib,re,json,sys
#simple script based on acoustid audio identification api and fpcalc tool
#download Chromaprint-fpcalc from https://acoustid.org/chromaprint
#you know ! it's just get fingerprint from audio file by fpcalc and make a request to acoustid as simple as that !
def main(file):
url = "https://api.acoustid.org/v2/lookup?client="
meta = "&meta=recordings"
api_key = "tOU4cqJKDT"
#to run fpcalc on windows or *nux
if os.name == "posix":
ru = "./"
else:
ru = ""
fp = os.popen(ru + "fpcalc '%s'" %file).read()
if len(fp) == 0:
exit()
data = re.sub("DURATION|FINGERPRINT", "" , fp).split('\n')
dur = data[0]
fp_ = data[1]
url += api_key + meta + "&duration" + dur + "&fingerprint" + fp_
name = json.loads(urllib.urlopen(url).read())
if name["status"] == "ok":
song = name["results"][0]["recordings"][0]["title"]
artist = name["results"][0]["recordings"][0]["artists"][0]["name"]
print song , "by" , artist
elif name["status"] == "":
print "no results"
if len(sys.argv) < 2 :
print 'fisic.py file'
exit()
else:
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment