diff --git a/src/artwork/cache.py b/src/artwork/cache.py index 806bb68..67dd49e 100644 --- a/src/artwork/cache.py +++ b/src/artwork/cache.py @@ -9,21 +9,33 @@ from __future__ import annotations import hashlib import logging import os -import tempfile logger = logging.getLogger(__name__) +def xdg_cache_path(subdir: str) -> str: + """Return path inside XDG cache directory for neo-pod-desktop. + Creates the directory structure if missing. + """ + base = os.environ.get( + "XDG_CACHE_HOME", + os.path.join(os.path.expanduser("~"), ".cache"), + ) + path = os.path.join(base, "neo-pod-desktop", subdir) + os.makedirs(path, exist_ok=True) + return path + + class CoverCache: """Manages a local cache of cover art images for the player UI. The cache stores JPEG thumbnails keyed by (artist, album) hash. + Covers are stored in $XDG_CACHE_HOME/neo-pod-desktop/covers/ + (default ~/.cache/neo-pod-desktop/covers/). """ def __init__(self, cache_dir: str | None = None): - self.cache_dir = cache_dir or os.path.join( - tempfile.gettempdir(), "neo-pod-covers" - ) + self.cache_dir = cache_dir or xdg_cache_path("covers") os.makedirs(self.cache_dir, exist_ok=True) def _key(self, artist: str, album: str) -> str: diff --git a/src/metadata_handler.py b/src/metadata_handler.py index 9671bec..dfc0a7a 100644 --- a/src/metadata_handler.py +++ b/src/metadata_handler.py @@ -7,7 +7,6 @@ Handles metadata injection and album art embedding import os import sys import logging -import tempfile import struct import base64 from typing import Optional, Dict, Any @@ -22,7 +21,7 @@ from mutagen.id3 import ID3, APIC, TIT2, TPE1, TALB, TRCK from mutagen.easyid3 import EasyID3 from youtube_downloader import TrackInfo -from artwork.cache import cover_cache +from artwork.cache import cover_cache, xdg_cache_path # Configure logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') @@ -39,7 +38,7 @@ class MetadataHandler: Args: temp_dir: Directory for temporary files (optional) """ - self.temp_dir = temp_dir or tempfile.gettempdir() + self.temp_dir = temp_dir or xdg_cache_path("thumbnails") os.makedirs(self.temp_dir, exist_ok=True) def download_thumbnail(self, thumbnail_url: str) -> Optional[str]: