Skip to content

Commit

Permalink
Store Media.downloaded_filesize for imported files
Browse files Browse the repository at this point in the history
Fixes #69
  • Loading branch information
tcely authored Feb 25, 2025
1 parent ff91cbf commit 533c163
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tubesync/sync/management/commands/import-existing-media.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def handle(self, *args, **options):
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():
Expand All @@ -38,7 +38,8 @@ def handle(self, *args, **options):
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:
Expand All @@ -50,7 +51,8 @@ def handle(self, *args, **options):
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')

0 comments on commit 533c163

Please sign in to comment.