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 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:

View File

@ -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]: