Make fpcalc missing page show up on startup instead of when viewing metadata, add metadata to file automatically with the downloader, fix lyrics caching

This commit is contained in:
csd4ni3l
2025-07-17 14:47:56 +02:00
parent 659f4e4462
commit 90c7859622
8 changed files with 115 additions and 81 deletions

View File

@@ -1,9 +1,7 @@
import os, platform, tarfile, acoustid, urllib.request, shutil, gzip, glob, logging, sys, io
import os, platform, acoustid, logging
from utils.constants import ACOUSTID_API_KEY
from zipfile import ZipFile
def get_fpcalc_name():
system = platform.system()
if system == "Linux" or system == "Darwin":
@@ -14,45 +12,7 @@ def get_fpcalc_name():
def get_fpcalc_path():
return os.path.join(os.getcwd(), "bin", get_fpcalc_name())
def download_fpcalc():
system = platform.system()
architecture = platform.machine()
if system == "Linux":
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-linux-x86_64.tar.gz"
elif system == "Darwin":
if architecture.lower() == "x86_64" or architecture.lower() == "amd64":
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-macos-x86_64.tar.gz"
else:
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-macos-arm64.tar.gz"
elif system == "Windows":
url = "https://github.com/acoustid/chromaprint/releases/download/v1.5.1/chromaprint-fpcalc-1.5.1-windows-x86_64.zip"
if url.endswith(".zip"):
zip_path = os.path.join(os.getcwd(), "bin", "chromaprint.zip")
urllib.request.urlretrieve(url, zip_path)
with ZipFile(zip_path) as file:
file.extractall(os.path.join(os.getcwd(), "bin"))
os.remove(zip_path)
else:
tar_gz_path = os.path.join(os.getcwd(), "bin", "chromaprint.tar.gz")
urllib.request.urlretrieve(url, tar_gz_path)
with gzip.open(tar_gz_path, "rb") as f: # For some reason, tarfile by itself didnt work for tar.gz so i have to uncompress with gzip first and then with tarfile
with tarfile.open(fileobj=io.BytesIO(f.read())) as tar:
tar.extractall(os.path.join(os.getcwd(), "bin"))
os.remove(tar_gz_path)
chromaprint_matches = glob.glob(os.path.join("bin", "chromaprint*"))
if chromaprint_matches:
shutil.move(os.path.join(chromaprint_matches[0], get_fpcalc_name()), os.path.join("bin", get_fpcalc_name()))
shutil.rmtree(chromaprint_matches[0])
os.chmod(get_fpcalc_path(), 0o755)
def get_recording_id_from_acoustic(filename):
def get_recording_id_from_acoustid(filename):
os.environ["FPCALC"] = get_fpcalc_path()
try: