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()