Compare commits

...

2 Commits

Author SHA1 Message Date
Erik Thuning
f8a29a983c Minor rework of thumbnail handling and a bit of pipeline order.
Fixed a bug causing the final package to point to an invalid thumb path
2022-04-26 11:18:27 +02:00
Erik Thuning
ba070d1611 whitespace nitpicking 2022-04-26 11:10:50 +02:00
3 changed files with 43 additions and 35 deletions

@ -80,12 +80,15 @@ class Pipeline:
# Add workbase to package
package = self.mkworkdir(package)
# Create thumbnail if none exists
package = self.thumbnailer.create_if_missing(package)
# Copy passed thumbnail to workdir or generate one
package = self.thumbnailer.pickup(package)
# Copy any passed subs to workdir
package = self.pickup_subs(package)
try:
# Transcoding and thumb generation
# Put new files in processing
# Transcoding and poster generation
# Put new files in workdir
# Update package with new relative names
package = self.transcoder.convert(package)
except ffmpeg.Error as e:
@ -105,9 +108,6 @@ class Pipeline:
exc_info=e)
return
# Pick up any passed subs
package = self.pickup_subs(package)
# If the job is an update, this will integrate unchanged originals
package = self.updater.integrate_update(package)
@ -131,8 +131,8 @@ class Pipeline:
return
# Finalize processing
# Remove base, workbase, orig_id, notification_id
# Save package to disk
# Move processing dir to processed
# Save package to workdir
# Move workdir to processed
# Delete queue file
# Delete base files
self.finalize(package)

@ -1,6 +1,7 @@
import logging
import os
import re
import shutil
import textwrap
from PIL import Image, ImageDraw, ImageFont
@ -31,7 +32,7 @@ def fix_outliers(text):
for (pat, rep) in modifiers:
text = re.sub(pat, rep, text)
return text
class Thumbnailer:
def __init__(self, config, ldap):
@ -46,32 +47,39 @@ class Thumbnailer:
self.descrbox = (1/8, 0.55,
7/8, 0.8)
def create_if_missing(self, package):
if not package['thumb']:
title = package['title']['sv']
description = package['description']
courses = ', '.join(package['courses'])
presenters = ', '.join([self.ldap.get_name(uid)
for uid in package['presenters']])
extras = []
if courses:
extras.append(courses)
if presenters:
extras.append(presenters)
extra = ': '.join(extras)
workbase = package['workbase']
def pickup(self, package):
thumb = package['thumb']
if thumb:
thumbfile = os.path.basename(thumb)
shutil.copy(os.path.join(package['base'], thumb),
os.path.join(package['workbase'], thumbfile))
package['thumb'] = thumbfile
return package
pres_id = package['id']
self.logger.debug('%s - Creating thumbnail', pres_id)
self.logger.debug('%s - Title: %s', pres_id, title)
self.logger.debug('%s - Description: %s', pres_id, description)
self.logger.debug('%s - Extra: %s', pres_id, extra)
package['thumb'] = self.make_thumb(workbase,
title, description, extra)
self.logger.info('%s - Thumbnail created', pres_id)
title = package['title']['sv']
description = package['description']
courses = ', '.join(package['courses'])
presenters = ', '.join([self.ldap.get_name(uid)
for uid in package['presenters']])
extras = []
if courses:
extras.append(courses)
if presenters:
extras.append(presenters)
extra = ': '.join(extras)
workbase = package['workbase']
pres_id = package['id']
self.logger.debug('%s - Creating thumbnail', pres_id)
self.logger.debug('%s - Title: %s', pres_id, title)
self.logger.debug('%s - Description: %s', pres_id, description)
self.logger.debug('%s - Extra: %s', pres_id, extra)
self.logger.info('%s - Thumbnail created', pres_id)
package['thumb'] = self._make_thumb(workbase,
title, description, extra)
return package
def make_thumb(self, workbase, title, description, extra):
def _make_thumb(self, workbase, title, description, extra):
with Image.open(self.base) as im:
draw = ImageDraw.Draw(im)

@ -49,8 +49,8 @@ class Transcoder:
maxheight, preset, crf))
_, ext = os.path.splitext(stream['poster'])
slides_poster = f'slides_poster{ext}'
shutil.copy2(stream['poster'],os.path.join(workbase,
slides_poster))
shutil.copy2(stream['poster'], os.path.join(workbase,
slides_poster))
stream['poster'] = slides_poster
# Remove the reference to the demuxfile since it is