1 from django.core.management.base import BaseCommand
2 from archive.constants import status
3 from archive.models import Audiobook
4 from youtube import tasks
7 class Command(BaseCommand):
8 help = "Schedules some audiobooks for uploading to YouTube."
10 def add_arguments(self, parser):
11 parser.add_argument("--limit", type=int, default=6)
13 def handle(self, *args, **options):
15 Audiobook.objects.filter(youtube_status=status.QUEUED)
16 .exclude(youtube_queued=None)
17 .order_by("youtube_queued")[: options["limit"]]
19 audiobook.youtube_task = tasks.YouTubeTask.delay(
20 None, audiobook.id, True
22 audiobook.youtube_status = status.WAITING
23 audiobook.save(update_fields=["youtube_task", "youtube_status"])