4e59f5fce38f58a3d8cfbb0219ba3c1bbd73aadd
[audio.git] / src / youtube / views.py
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
9
10
11
12 @require_POST
13 @permission_required('archive.change_audiobook')
14 def publish(request, aid, publish=True):
15     audiobook = get_object_or_404(Audiobook, id=aid)
16     tags = {}
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]))
23
24
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')