From a4d3e987097959b2d29eda1623e726a065c09a31 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 25 Apr 2018 18:24:53 +0200 Subject: transcode twitch & logging --- odin/strm/download_youtube | 54 +++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/odin/strm/download_youtube b/odin/strm/download_youtube index 1d729fee..357988d4 100644 --- a/odin/strm/download_youtube +++ b/odin/strm/download_youtube @@ -17,21 +17,13 @@ function notmuch { done } -logTag=${0:t} - -exec 1> >(logger -t "$logTag" -p news.notice) -exec 2> >(logger -t "$logTag" -p news.error) - -debug() { logger -t "$logTag" -p news.debug } -warn() { logger -t "$logTag" -p news.warn } - typeset -a cleanupCmds cleanupCmds=() function doCleanup { for cmd (${cleanupCmds}); do - # print -- ${cmd} | debug - eval $cmd | debug + # print -- ${cmd} + eval $cmd done } @@ -74,13 +66,13 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" msgTags=($(notmuch search --output=tags $msgId )) if [[ ${msgTags[(i)cached]} -le $#msgTags ]]; then - print "Message in Cache" | warn + print "Message in Cache" >&2 exit 0 fi if [[ 'base64' == $(sed '/^Content-Transfer-Encoding: */!d; s///;q' ${message}) ]]; then tmpFile=$(mktemp --tmpdir=/home/gkleen/rss/tmp .writeOut.XXXXXX) - printf "Decoding base64 message content for ‘%s’" ${message} | debug + printf "Decoding base64 message content for ‘%s’" ${message} sed '/^Content-Transfer-Encoding: */d; /^$/q' ${message} >! $tmpFile sed '1,/^$/d' ${message} | base64 -d >> $tmpFile mv -v $tmpFile ${message} @@ -96,10 +88,10 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" sld=$(cut -d '/' -f 3 <<<${url} | rev | cut -d '.' -f 1-2 | rev) if [[ -e ${HOME}/.dl-backup ]] && grep -q ${sld} ${HOME}/.dl-backup; then - printf "Was told to back up off %s\n" ${sld} | warn + printf "Was told to back up off %s\n" ${sld} >&2 exit 0 else - printf "Proceeding on %s\n" ${sld} | debug + printf "Proceeding on %s\n" ${sld} fi dir="/srv/media/youtube" @@ -144,15 +136,15 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" printf "%s\n%s via %s: %s\nExpecting ‘%s’\n" ${title} ${videoId} ${extractor} ${format} ${filename:t} if [[ -n ${extractor} && -n ${videoId} ]]; then - printf "Searching for %s on %s in cache...\n" ${videoId} ${extractor} | debug + printf "Searching for %s on %s in cache...\n" ${videoId} ${extractor} typeset -a messages messages=($(notmuch search --output=messages -- from:${extractor} and ${videoId} and is:cached)) if [[ ${#messages} -ne 0 ]]; then - printf "Video already cached: %s\n" "${messages[*]}" | warn + printf "Video already cached: %s\n" "${messages[*]}" >&2 else - printf "Video not yet cached\n" | debug + printf "Video not yet cached\n" fi fi @@ -175,7 +167,7 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" done fi - [[ -n ${filename} ]] && printf "Found ‘%s’\n" ${filename:t} || debug + [[ -n ${filename} ]] && printf "Found ‘%s’\n" ${filename:t} # newFilename=${filename:h}/$(mungefilename ${filename:t}) # if [[ "${filename}" != "${newFilename}" ]]; then @@ -199,17 +191,19 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" extensions=("mp4") fi - if [[ "${bare_amp}" -ne 0 || ${extensions[(i)${filename:e}]} -gt ${#extensions} ]]; then - printf "Transcoding ‘%s’" ${title} | debug + typeset -a transcodeExtractors + transcodeExtractors=("twitch -vod") + + if [[ "${bare_amp}" -ne 0 || ${extensions[(i)${filename:e}]} -gt ${#extensions} || ${transcodeExtractors[(i)${extractor}]} -le ${#transcodeExtractors} ]]; then + printf "Transcoding ‘%s’" ${title} printf "%d %d %d/%d(%d)…\n" \ $([[ $($alwaysTranscode; print $?) -eq 0 ]]; print $?) \ $([[ "${bare_amp}" -ne 0 ]]; print $?) \ ${extensions[(i)${filename:e}]} ${#extensions} \ - $([[ ${extensions[(i)${filename:e}]} -gt ${#extensions} ]]; print $?) \ - | debug + $([[ ${extensions[(i)${filename:e}]} -gt ${#extensions} ]]; print $?) tempfile=$(mktemp --tmpdir=${filename:h} .transcode.${filename:t:r}.$$.XXXXXX.${filename:e}) cleanup rm -v -- "${tempfile}" - mv -vf "${filename}" "${tempfile}" | debug + mv -vf "${filename}" "${tempfile}" typeset -A fileInfo for line ($(@ffmpeg@/bin/ffprobe -v error -show_format -show_streams -show_entries stream=codec_name,codec_type:format=:stream_tags=:stream_disposition=:format_tags= -of flat=h=0 -- ${tempfile})); do @@ -234,7 +228,7 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" local cType=${fileInfo[${formatKey}]} local cName=${fileInfo[stream.${i}.codec_name]} - printf "Stream %d: %s (%s)\n" ${i} ${cName} ${cType} | debug + printf "Stream %d: %s (%s)\n" ${i} ${cName} ${cType} if [[ ${cType} == "video" ]]; then if [[ ${ext} == "mkv" ]]; then @@ -289,22 +283,22 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" cleanup rm -rfv -- ${PWD} p1args+=(-an -f matroska) - print -- ${prePass} ${p1args} | debug + print -- ${prePass} ${p1args} ffmpeg ${args} ${prePass} ${p1args} -- /dev/null - print -- ${cargs} ${p2args} | debug + print -- ${cargs} ${p2args} ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" cd ${oldPwd} else args+=(-v warning -i pipe:0) - print -- ${cargs} ${p2args} | debug + print -- ${cargs} ${p2args} pv -N "$(trimName "trans:" ${title})" ${tempfile} | ffmpeg ${args} ${cargs} ${p2args} -- "${filename}" fi fi - chmod -v 644 "${filename}" | debug + chmod -v 644 "${filename}" tmpFile=$(mktemp --tmpdir=/home/gkleen/rss/tmp .insertUrl.$$.XXXXXX) relUrl=$(realpath --relative-to=/srv/media ${filename}) typeset -a relUrlComponents @@ -315,7 +309,7 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" relUrl+=$(sed -f ${HOME}/url_escape.sed <<<${urlPiece}) done awk -v "link=http://odin.asgard.yggdrasil/${relUrl}" '{ if (r == 0) { r = gsub("href=\"[^\"]+\"", "href=\"" link "\""); }; print; }' "${message}" >! $tmpFile - mv -v $tmpFile $message | debug + mv -v $tmpFile $message notmuch tag '+cached' -- $msgId && printf "Tagged ‘%s’ as 'cached'" ${msgId} if [[ -n "$(notmuch search "tag:inbox AND $msgId")" ]]; then @@ -328,7 +322,7 @@ printf ">>> %s <<<\n %s\n" "${msgId}" "${message}" fi systemctl --no-block start uucico@hel.service else - print "Message vanished from inbox" | warn + print "Message vanished from inbox" >&2 fi else printf "An error occured while downloading video at ‘%s’ (exitcode: %d)\n" ${url} ${ytResult} >&2 -- cgit v1.2.3