Add: managment command to back fill video & gif thumb generation

This commit is contained in:
Aroy-Art 2025-03-11 20:56:25 +01:00
parent b6b8b5918c
commit a404dcf09b
Signed by: Aroy
GPG key ID: 583642324A1D2070
3 changed files with 22 additions and 0 deletions

View file

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