+ def update_thumbnail(self, audiobook):
+ thumbnail = self.prepare_thumbnail(audiobook)
+ response = youtube_call(
+ "POST",
+ "https://www.googleapis.com/upload/youtube/v3/thumbnails/set",
+ params={'videoId': audiobook.youtube_id},
+ data=thumbnail.getvalue(),
+ )
+
+ def prepare_thumbnail(self, audiobook):
+ img = create_thumbnail(
+ self.thumbnail_template.path,
+ self.thumbnail_definition,
+ {
+ "author": ', '.join((a['name'] for a in audiobook.book['authors'])),
+ "title": audiobook.book['title'],
+ "part": (audiobook.youtube_volume or audiobook.part_name).strip(),
+ },
+ lambda name: Font.objects.get(name=name).truetype.path
+ )
+ buf = io.BytesIO()
+ img.save(buf, format='PNG')
+ return buf
+