fix
[audio.git] / src / youtube / management / commands / youtube.py
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
5
6
7 class Command(BaseCommand):
8     help = "Schedules some audiobooks for uploading to YouTube."
9
10     def add_arguments(self, parser):
11         parser.add_argument("--limit", type=int, default=6)
12
13     def handle(self, *args, **options):
14         for audiobook in (
15             Audiobook.objects.filter(youtube_status=status.QUEUED)
16             .exclude(youtube_queued=None)
17             .order_by("youtube_queued")[: options["limit"]]
18         ):
19             tasks.YouTubeTask.delay(
20                 None, audiobook.id, True
21             ).task_id
22             audiobook.youtube_status = status.WAITING
23             audiobook.save(update_fields=["youtube_status"])