discoverylidarr/musicbrainz_helpers.py

33 lines
891 B
Python
Raw Permalink Normal View History

2025-06-25 15:03:26 +02:00
#musicbrainz_helpers.py
2025-06-23 10:31:25 +02:00
import json
from pathlib import Path
CACHE_FILE = Path(__file__).resolve().parent / "cache.json"
def load_cache():
try:
if not CACHE_FILE.exists():
with open(CACHE_FILE, "w") as f:
2025-06-25 15:03:26 +02:00
json.dump({
"added_artists": [],
"similar_cache": {},
"added_tracks": []
}, f)
2025-06-23 10:31:25 +02:00
with open(CACHE_FILE, "r") as f:
2025-06-25 13:25:04 +00:00
data = json.load(f)
data.setdefault("added_artists", [])
data.setdefault("similar_cache", {})
data.setdefault("added_tracks", [])
return data
2025-06-23 10:31:25 +02:00
except Exception:
2025-06-25 15:03:26 +02:00
return {
"added_artists": [],
"similar_cache": {},
"added_tracks": []
}
2025-06-25 13:25:04 +00:00
def save_cache(cache):
with open(CACHE_FILE, "w") as f:
json.dump(cache, f, indent=2)