4a8dfb58a5341575eb31eba3f0bb1e8d4a1475a6
[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 Audiobook.objects.exclude(youtube_queued=None).order_by(
15             "youtube_queued"
16         )[: options["limit"]]:
17             audiobook.youtube_task = tasks.YouTubeTask.delay(
18                 None, audiobook.id, True
19             ).task_id
20             audiobook.youtube_status = status.WAITING
21             audiobook.save(update_fields=["youtube_task", "youtube_status"])