X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/ff4fa4a4ae20cfb529d495f335cce477ada7f6a1..e7e2c234192c3e71cd69376eac9208a996eea935:/src/youtube/management/commands/youtube.py?ds=sidebyside diff --git a/src/youtube/management/commands/youtube.py b/src/youtube/management/commands/youtube.py index 4a8dfb5..c480830 100644 --- a/src/youtube/management/commands/youtube.py +++ b/src/youtube/management/commands/youtube.py @@ -11,11 +11,13 @@ class Command(BaseCommand): parser.add_argument("--limit", type=int, default=6) def handle(self, *args, **options): - for audiobook in Audiobook.objects.exclude(youtube_queued=None).order_by( - "youtube_queued" - )[: options["limit"]]: - audiobook.youtube_task = tasks.YouTubeTask.delay( + for audiobook in ( + Audiobook.objects.filter(youtube_status=status.QUEUED) + .exclude(youtube_queued=None) + .order_by("youtube_queued")[: options["limit"]] + ): + tasks.YouTubeTask.delay( None, audiobook.id, True ).task_id audiobook.youtube_status = status.WAITING - audiobook.save(update_fields=["youtube_task", "youtube_status"]) + audiobook.save(update_fields=["youtube_status"])