summaryrefslogtreecommitdiff
path: root/odin/strm/send_kitty
blob: a1b7e836c03d0e9e9374dcfd6c59367066970fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!@zsh@/bin/zsh

set -o errexit
umask 022

ffmpeg() { { { @ffmpeg@/bin/ffmpeg $@ 1>&3 } 2>&1 | stdbuf -o 0 tr '\r' '\n' | grep -v --line-buffered -E '^$' 1>&2 } 3>&1 }

wDir=/srv/hlidskjalf
concatDir=${wDir}/concat
lastFile=${concatDir}/latest.mkv

fList=""
tmpFile=""

function cleanup() {
    [[ -n "${fList}" ]] && rm -fv ${fList}
    [[ -n "${tmpFile}" ]] && rm -fv ${tmpFile}
}

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}

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"
tmpFile=$(mktemp --tmpdir=${concatDir} "${newfile:h}/.${newFile:t:r}.XXXXXX.mkv")

ffmpeg -y -safe 0 -f concat -i =(awk $'{ print "file \'"$0"\'" }' ${fList}) -c:v libx264 -r 30 -crf 27 -preset veryfast -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")" ${tmpFile}
chmod 440 ${tmpFile}
mv -v ${tmpFile} ${newFile}
queue.hel -p -r ${newFile}
ln -vfs $(realpath --relative-to=${lastFile:h} ${newFile}) ${lastFile}