From a404dcf09b2cc8db465dfa5d2fb5b08d75742a93 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Tue, 11 Mar 2025 20:56:25 +0100 Subject: [PATCH] Add: managment command to back fill video & gif thumb generation --- backend/apps/files/management/__init__.py | 0 .../files/management/commands/__init__.py | 0 .../commands/backfill_video_thumbs.py | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 backend/apps/files/management/__init__.py create mode 100644 backend/apps/files/management/commands/__init__.py create mode 100644 backend/apps/files/management/commands/backfill_video_thumbs.py diff --git a/backend/apps/files/management/__init__.py b/backend/apps/files/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/apps/files/management/commands/__init__.py b/backend/apps/files/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/apps/files/management/commands/backfill_video_thumbs.py b/backend/apps/files/management/commands/backfill_video_thumbs.py new file mode 100644 index 0000000..bb2c8bb --- /dev/null +++ b/backend/apps/files/management/commands/backfill_video_thumbs.py @@ -0,0 +1,22 @@ +from django.core.management.base import BaseCommand +from apps.files.tasks import generate_video_thumbnail +from apps.files.models import PostFileModel +from tqdm import tqdm + + +class Command(BaseCommand): + help = "Backfill video and gif thumbs" + + def handle(self, *args, **options): + # Get all PostFileModel instances that need thumbs + files = PostFileModel.objects.filter(file_type__in=["video", "gif"]) + + # Create a progress bar + pbar = tqdm(total=files.count(), desc="Generating thumbs") + + # Loop through each file and generate thumbs + for file in files: + generate_video_thumbnail.delay(file.id) + pbar.update(1) + + pbar.close()