[importers] WebDAV for retroarch should stash in procesesd now
This commit is contained in:
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user