refactor: dynamic iOpenPod discovery, add to requirements
- Replace hardcoded /tmp/iOpenPod with importlib.util.find_spec lookup with fallback to /tmp/iOpenPod and ~/iOpenPod for dev/backward compat - Add iopenpod>=1.0.53 to requirements.txt - Remove deprecated mkdir temp/downloads/converted from install.sh (all paths now XDG-compliant)
This commit is contained in:
parent
cbc888660f
commit
e3666c8c64
@ -39,10 +39,6 @@ source venv/bin/activate
|
||||
echo "Installing dependencies..."
|
||||
pip3 install -r requirements.txt
|
||||
|
||||
# Create necessary directories
|
||||
echo "Creating necessary directories..."
|
||||
mkdir -p temp downloads converted
|
||||
|
||||
echo ""
|
||||
echo "Installation complete!"
|
||||
echo ""
|
||||
|
||||
@ -10,3 +10,4 @@ tqdm>=4.65.0
|
||||
musicbrainzngs>=0.7.1
|
||||
PyQt6>=6.5.0
|
||||
numpy>=1.24.0
|
||||
iopenpod>=1.0.53
|
||||
|
||||
@ -21,6 +21,7 @@ Public API preserved for main.py compatibility:
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
import hashlib
|
||||
@ -38,7 +39,33 @@ from mutagen.easyid3 import EasyID3
|
||||
|
||||
from artwork import prepare_artwork_for_track, ArtworkEntry, write_artworkdb
|
||||
|
||||
_IOP_ROOT = "/tmp/iOpenPod"
|
||||
def _find_iop_root() -> str:
|
||||
"""Find iOpenPod's installed location.
|
||||
|
||||
Tries in order:
|
||||
1. pip-installed package (via importlib.util.find_spec)
|
||||
2. /tmp/iOpenPod (backward compat / development)
|
||||
"""
|
||||
for pkg in ("iTunesDB_Writer", "SQLiteDB_Writer", "ipod_device"):
|
||||
spec = importlib.util.find_spec(pkg)
|
||||
if spec and spec.origin:
|
||||
parent = os.path.dirname(spec.origin)
|
||||
if os.path.basename(parent) == pkg:
|
||||
return os.path.dirname(parent)
|
||||
|
||||
fallbacks = [
|
||||
"/tmp/iOpenPod",
|
||||
os.path.join(os.path.expanduser("~"), "iOpenPod"),
|
||||
]
|
||||
for path in fallbacks:
|
||||
if os.path.isdir(path):
|
||||
return path
|
||||
|
||||
raise ImportError(
|
||||
"iOpenPod not found. Install with: pip install iopenpod"
|
||||
)
|
||||
|
||||
_IOP_ROOT = _find_iop_root()
|
||||
_IOP_CACHE: dict[str, Any] = {}
|
||||
_IOP_READY = False
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user