+
+
+def thumbnail(request, aid):
+ audiobook = get_object_or_404(Audiobook, id=aid)
+ yt = models.YouTube.objects.first()
+ buf = yt.prepare_thumbnail(audiobook)
+ return HttpResponse(buf.getvalue(), content_type='image/png')
+
+
+class Preview(DetailView):
+ model = Audiobook
+ template_name = 'youtube/preview.html'
+
+ def get_context_data(self, **kwargs):
+ ctx = super().get_context_data(**kwargs)
+ yt = models.YouTube.objects.first()
+ ctx['data'] = yt.get_data(ctx['object'])
+ ctx['title'] = yt.get_title(ctx['object'])
+ ctx['description'] = yt.get_description(ctx['object'])
+ return ctx
+
+
+@method_decorator(permission_required('archive.change_audiobook'), name='dispatch')
+class Update(SingleObjectMixin, View):
+ model = Audiobook
+
+ def post(self, request, pk):
+ yt = models.YouTube.objects.first()
+ yt.update_data(self.get_object())
+ return redirect(reverse('file', args=[pk]))