Move cover cache and temp files from /tmp to XDG cache (~/.cache/neo-pod-desktop/)

- Add xdg_cache_path() utility respecting
- CoverCache now stores covers in ~/.cache/neo-pod-desktop/covers/
- MetadataHandler temp files in ~/.cache/neo-pod-desktop/thumbnails/
- Survives reboot, no more lost cover_path during process_file
This commit is contained in:
Maksim Totmin 2026-05-31 23:16:42 +07:00
parent 6a841afaa0
commit 8cc4ef5279
2 changed files with 18 additions and 7 deletions

View File

@ -9,21 +9,33 @@ from __future__ import annotations
import hashlib import hashlib
import logging import logging
import os import os
import tempfile
logger = logging.getLogger(__name__) 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: class CoverCache:
"""Manages a local cache of cover art images for the player UI. """Manages a local cache of cover art images for the player UI.
The cache stores JPEG thumbnails keyed by (artist, album) hash. 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): def __init__(self, cache_dir: str | None = None):
self.cache_dir = cache_dir or os.path.join( self.cache_dir = cache_dir or xdg_cache_path("covers")
tempfile.gettempdir(), "neo-pod-covers"
)
os.makedirs(self.cache_dir, exist_ok=True) os.makedirs(self.cache_dir, exist_ok=True)
def _key(self, artist: str, album: str) -> str: def _key(self, artist: str, album: str) -> str:

View File

@ -7,7 +7,6 @@ Handles metadata injection and album art embedding
import os import os
import sys import sys
import logging import logging
import tempfile
import struct import struct
import base64 import base64
from typing import Optional, Dict, Any 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 mutagen.easyid3 import EasyID3
from youtube_downloader import TrackInfo from youtube_downloader import TrackInfo
from artwork.cache import cover_cache from artwork.cache import cover_cache, xdg_cache_path
# Configure logging # Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@ -39,7 +38,7 @@ class MetadataHandler:
Args: Args:
temp_dir: Directory for temporary files (optional) 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) os.makedirs(self.temp_dir, exist_ok=True)
def download_thumbnail(self, thumbnail_url: str) -> Optional[str]: def download_thumbnail(self, thumbnail_url: str) -> Optional[str]: