32 lines
891 B
Python
32 lines
891 B
Python
#musicbrainz_helpers.py
|
|
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:
|
|
json.dump({
|
|
"added_artists": [],
|
|
"similar_cache": {},
|
|
"added_tracks": []
|
|
}, f)
|
|
with open(CACHE_FILE, "r") as f:
|
|
data = json.load(f)
|
|
data.setdefault("added_artists", [])
|
|
data.setdefault("similar_cache", {})
|
|
data.setdefault("added_tracks", [])
|
|
return data
|
|
except Exception:
|
|
return {
|
|
"added_artists": [],
|
|
"similar_cache": {},
|
|
"added_tracks": []
|
|
}
|
|
|
|
def save_cache(cache):
|
|
with open(CACHE_FILE, "w") as f:
|
|
json.dump(cache, f, indent=2)
|
|
|