[importers] WebDAV for retroarch should stash in procesesd now
All checks were successful
build & deploy / test (push) Successful in 2m18s
build & deploy / build-and-deploy (push) Successful in 49s

This commit is contained in:
2026-05-31 12:09:56 -04:00
parent bca90c97ae
commit 263874288a
2 changed files with 35 additions and 5 deletions

View File

@ -330,13 +330,19 @@ def scan_webdav_for_retroarch(webdav_client, user_id, update_hash_only=False):
from scrobbles.models import RetroarchImport
from scrobbles.tasks import process_retroarch_import
retroarch_path = DEFAULT_RETROARCH_PATH + "playlogs/"
retroarch_path = DEFAULT_RETROARCH_PATH
processed_dir = f"{retroarch_path}processed/"
try:
webdav_client.info(retroarch_path)
except:
logger.info("No var/retroarch/ directory on webdav", extra={"user_id": user_id})
return 0
try:
webdav_client.mkdir(processed_dir, recursive=True)
except Exception:
pass
try:
files = webdav_client.list(retroarch_path, get_info=True)
except Exception as e:
@ -346,6 +352,11 @@ def scan_webdav_for_retroarch(webdav_client, user_id, update_hash_only=False):
)
return 0
# Extract basename from path since the webdav adapter returns name=None
for f in files:
if f.get("path") and not f.get("name"):
f["name"] = os.path.basename(f["path"])
lrtl_files = sorted(
[f for f in files if (f.get("name") or "").lower().endswith(".lrtl")],
key=lambda x: (x.get("name") or ""),
@ -400,15 +411,25 @@ def scan_webdav_for_retroarch(webdav_client, user_id, update_hash_only=False):
download_dir = tempfile.mkdtemp()
try:
downloaded = []
imported_filenames = []
for f in lrtl_files:
basename = f.get("name")
remote_path = f"{retroarch_path}{basename}"
dst = os.path.join(download_dir, basename)
try:
webdav_client.download_sync(
remote_path=f.get("path"),
remote_path=remote_path,
local_path=dst,
)
downloaded.append(basename)
ts = datetime.now().strftime("%Y%m%d%H%M%S")
processed_name = f"{ts}-{basename}"
imported_filenames.append(processed_name)
webdav_client.move(
remote_path,
f"{processed_dir}{processed_name}",
)
except Exception as e:
logger.error("Failed to download retroarch %s: %s", basename, e)
@ -425,7 +446,7 @@ def scan_webdav_for_retroarch(webdav_client, user_id, update_hash_only=False):
imp = RetroarchImport.objects.create(
user_id=user_id,
original_filename=f"batch-{len(downloaded)}-files",
original_filename=", ".join(imported_filenames),
files_hash=content_hash,
)
with open(zip_path, "rb") as f: