From 533c1631b729a506bcc5eb36a63d6e2099ad71ee Mon Sep 17 00:00:00 2001 From: tcely Date: Tue, 25 Feb 2025 04:13:02 -0500 Subject: [PATCH] Store `Media.downloaded_filesize` for imported files Fixes #69 --- .../sync/management/commands/import-existing-media.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tubesync/sync/management/commands/import-existing-media.py b/tubesync/sync/management/commands/import-existing-media.py index 6b723e70..fd6a800d 100644 --- a/tubesync/sync/management/commands/import-existing-media.py +++ b/tubesync/sync/management/commands/import-existing-media.py @@ -16,7 +16,7 @@ class Command(BaseCommand): log.info('Building directory to Source map...') dirmap = {} for s in Source.objects.all(): - dirmap[s.directory_path] = s + dirmap[str(s.directory_path)] = s log.info(f'Scanning sources...') file_extensions = list(FileExtension.values) + self.extra_extensions for sourceroot, source in dirmap.items(): @@ -38,7 +38,8 @@ class Command(BaseCommand): ext = ext.strip().lower() if ext not in file_extensions: continue - on_disk.append(str(rootpath / filename)) + filepath = Path(rootpath / filename).resolve(strict=True) + on_disk.append(str(filepath)) filemap = {} for item in media: for filepath in on_disk: @@ -50,7 +51,8 @@ class Command(BaseCommand): for filepath, item in filemap.items(): log.info(f'Matched on-disk file: {filepath} ' f'to media item: {item.source} / {item}') - item.media_file.name = filepath + item.media_file.name = str(Path(filepath).relative_to(item.media_file.storage.location)) item.downloaded = True + item.downloaded_filesize = Path(filepath).stat().st_size item.save() log.info('Done')