1 from django.contrib.auth.decorators import permission_required
2 from django.http import HttpResponse
3 from django.shortcuts import redirect, get_object_or_404
4 from django.urls import reverse
5 from django.views.decorators.http import require_POST
6 from archive.constants import status
7 from archive.models import Audiobook
8 from . import models, tasks
13 @permission_required('archive.change_audiobook')
14 def publish(request, aid, publish=True):
15 audiobook = get_object_or_404(Audiobook, id=aid)
17 #audiobook.set_youtube_tags(tags)
18 audiobook.youtube_status = status.WAITING
19 audiobook.save(update_fields=['youtube_status'])
20 audiobook.youtube_task = tasks.YouTubeTask.delay(request.user.id, aid, publish).task_id
21 audiobook.save(update_fields=['youtube_task'])
22 return redirect(reverse('file', args=[aid]))
25 def thumbnail(request, aid):
26 audiobook = get_object_or_404(Audiobook, id=aid)
27 yt = models.YouTube.objects.first()
28 buf = yt.prepare_thumbnail(audiobook)
29 return HttpResponse(buf.getvalue(), content_type='image/png')