+ if thumbnail_id is None:
+ yt = audiobook.project.youtube
+ buf = yt.prepare_thumbnail(audiobook)
+ else:
+ template = get_object_or_404(models.ThumbnailTemplate, id=thumbnail_id)
+ buf = template.generate(audiobook)
+ buf = buf.getvalue() if buf is not None else b''
+ return HttpResponse(buf, 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 = ctx['object'].project.youtube
+ ctx['data'] = yt.get_data(ctx['object'])
+ ctx['title'] = yt.get_title(ctx['object'])
+ ctx['description'] = yt.get_description(ctx['object'])
+ ctx['templates'] = models.ThumbnailTemplate.objects.all()
+ return ctx
+
+
+@method_decorator(permission_required('archive.change_audiobook'), name='dispatch')
+class Update(SingleObjectMixin, View):
+ model = Audiobook
+
+ def post(self, request, pk):
+ obj = self.get_object()
+ yt = obj.project.youtube
+ yt.update_data(obj)
+ return redirect(reverse('file', args=[pk]))
+
+
+@method_decorator(permission_required('archive.change_audiobook'), name='dispatch')
+class UpdateThumbnail(SingleObjectMixin, View):
+ model = Audiobook
+
+ def post(self, request, pk):
+ obj = self.get_object()
+ yt = obj.project.youtube
+ yt.update_thumbnail(obj)
+ return redirect(reverse('file', args=[pk]))