[tasks] Move retroarch importing to webdav
This commit is contained in:
@ -399,6 +399,9 @@ class RetroarchImport(BaseFileImportMixin):
|
||||
def get_absolute_url(self):
|
||||
return reverse("scrobbles:retroarch-import-detail", kwargs={"slug": self.uuid})
|
||||
|
||||
original_filename = models.CharField(max_length=255, **BNULL)
|
||||
lrtl_file = models.FileField(upload_to="scrobbles/lrtl_file/", **BNULL)
|
||||
|
||||
def process(self, import_all=False, force=False):
|
||||
"""Import scrobbles found on Retroarch"""
|
||||
if self.user.id == 1:
|
||||
@ -411,17 +414,39 @@ class RetroarchImport(BaseFileImportMixin):
|
||||
if force:
|
||||
logger.info(f"You told me to force import from Retroarch")
|
||||
|
||||
if not self.user.profile.retroarch_path:
|
||||
logger.info(
|
||||
"Tying to import Retroarch logs, but user has no retroarch_path configured"
|
||||
)
|
||||
|
||||
self.mark_started()
|
||||
|
||||
scrobbles = retroarch.import_retroarch_lrtl_files(
|
||||
self.user.profile.retroarch_path,
|
||||
self.user.id,
|
||||
)
|
||||
if self.lrtl_file:
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
try:
|
||||
src_path = self.lrtl_file.path
|
||||
basename = self.original_filename or os.path.basename(src_path)
|
||||
dst = os.path.join(tmpdir, basename)
|
||||
with open(dst, "wb") as f:
|
||||
f.write(self.lrtl_file.read())
|
||||
scrobbles = retroarch.import_retroarch_lrtl_files(
|
||||
tmpdir + "/",
|
||||
self.user.id,
|
||||
)
|
||||
finally:
|
||||
import shutil
|
||||
|
||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||
else:
|
||||
if not self.user.profile.retroarch_path:
|
||||
logger.info(
|
||||
"Tying to import Retroarch logs, but user has no retroarch_path configured"
|
||||
)
|
||||
self.mark_finished()
|
||||
return
|
||||
|
||||
scrobbles = retroarch.import_retroarch_lrtl_files(
|
||||
self.user.profile.retroarch_path,
|
||||
self.user.id,
|
||||
)
|
||||
|
||||
self.record_log(scrobbles)
|
||||
self.mark_finished()
|
||||
|
||||
Reference in New Issue
Block a user