Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Created March 12, 2025 14:53
Show Gist options
  • Save ZiTAL/9ecf3ed315502be9047bb926609cbecf to your computer and use it in GitHub Desktop.
Save ZiTAL/9ecf3ed315502be9047bb926609cbecf to your computer and use it in GitHub Desktop.
acoustid API: how to change mp3 metadata
# apt-get install libchromaprint-tools
# pip install requests mutagen
# api key: https://acoustid.org/new-application
import json
import requests
import subprocess
from mutagen.easyid3 import EasyID3
ACOUSTID_API_KEY = "API_KEY"
def get_acoustid_metadata(file_path):
result = subprocess.run(["fpcalc", "-json", file_path], capture_output=True, text=True)
if result.returncode != 0:
print(f"Error processing {file_path}")
return None
fpcalc = json.loads(result.stdout)
response = requests.get("https://api.acoustid.org/v2/lookup", params={
"client": ACOUSTID_API_KEY,
"fingerprint": fpcalc['fingerprint'],
"meta": "recordings",
"duration": int(fpcalc['duration'])
}).json()
print(response)
if response["status"] == "ok" and response["results"]:
return response["results"][0]["recordings"][0]
return None
def tag_mp3(file_path):
metadata = get_acoustid_metadata(file_path)
if metadata:
audio = EasyID3(file_path)
audio["title"] = metadata["title"]
audio["artist"] = metadata["artists"][0]["name"]
audio.save()
print(f"Updated: {file_path}")
import glob
for file in glob.glob("*.mp3"):
tag_mp3(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment