#!@zsh@/bin/zsh set -o errexit umask 022 wDir=/srv/hlidskjalf concatDir=${wDir}/concat lastFile=${concatDir}/latest.mkv fList="" function cleanup() { [[ -n "${fList}" ]] && rm -v ${fList} } trap cleanup EXIT fList=$(mktemp --tmpdir filelist.XXXXXX) typeset -a findArg findArg=() if [[ -e ${lastFile} ]]; then findArg=(-mtime -1 -a -newer ${lastFile}) else findArg=(-mtime -1) fi find -L /srv/hlidskjalf \( -path /srv/hlidskjalf/concat -prune \) -o \( \( ${findArg} \) -type f -print \) | sort | >! ${fList} cat ${fList} >&2 if [[ $(wc -l ${fList} | cut -d ' ' -f 1) -eq 0 ]]; then exit 0 fi newFile="${concatDir}/hlidskjalf.$(date +'%Y-%m-%d-%H-%M-%S').mkv" @ffmpeg@/bin/ffmpeg -safe 0 -f concat -i =(awk $'{ print "file \'"$0"\'" }' ${fList}) -c:v libx264 -r 30 -vf 'scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2' -metadata "description=$(xargs -a ${fList} -- basename -s ".mkv")" ${newFile} queue.hel -p -r ${newFile} ln -vfs $(realpath --relative-to=${lastFile:h} ${newFile}) ${lastFile}