Enable logging for all output

pull/11/head
RandomNinjaAtk 4 years ago committed by GitHub
parent ebcebe947b
commit 772a40ac2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,8 +6,8 @@ TITLESHORT="VPP"
set -e set -e
Configuration () { Configuration () {
log "############################################ SABnzbd Job: $1" log "############################################ SABnzbd Job: $jobname"
log "############################################ SABnzbd Category: $2" log "############################################ SABnzbd Category: $category"
log "############################################ DOCKER: $TITLE" log "############################################ DOCKER: $TITLE"
log "############################################ SCRIPT: Video Post Processor ($TITLESHORT)" log "############################################ SCRIPT: Video Post Processor ($TITLESHORT)"
log "############################################ SCRIPT VERSION: 1.0.0" log "############################################ SCRIPT VERSION: 1.0.0"
@ -40,327 +40,335 @@ Configuration () {
log () { log () {
m_time=`date "+%F %T"` m_time=`date "+%F %T"`
echo $m_time" "$1 | tee -a /config/scripts/logs/video-pp.log echo $m_time" "$1
chmod 666 /config/scripts/logs/video-pp.log
chown abc:abc /config/scripts/logs/video-pp.log
} }
Configuration "$3" "$5" Main () {
folderpath="$1"
jobname="$3"
category="$5"
Configuration
if [ ${VIDEO_SMA} = TRUE ]; then if [ ${VIDEO_SMA} = TRUE ]; then
touch "$1/sma-conversion-check" touch "$1/sma-conversion-check"
elif [ ${VIDEO_MKVCLEANER} = TRUE ]; then elif [ ${VIDEO_MKVCLEANER} = TRUE ]; then
touch "$1/sma-conversion-check" touch "$1/sma-conversion-check"
fi fi
# check for video files # check for video files
if find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\|avi\)" | read; then if find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\|avi\)" | read; then
sleep 0.1 sleep 0.1
else else
log "ERROR: No video files found for processing" log "ERROR: No video files found for processing"
exit 1 exit 1
fi fi
filecount=$(find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\|avi\)" | wc -l) filecount=$(find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\|avi\)" | wc -l)
log "Processing ${filecount} video files..." log "Processing ${filecount} video files..."
count=0 count=0
find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\|avi\)" -print0 | while IFS= read -r -d '' video; do find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\|avi\)" -print0 | while IFS= read -r -d '' video; do
count=$(($count+1)) count=$(($count+1))
log "" log ""
log "====================================================" log "===================================================="
basefilename="${video%.*}" basefilename="${video%.*}"
filename="$(basename "$video")" filename="$(basename "$video")"
extension="${filename##*.}" extension="${filename##*.}"
log "Begin processing $count of $filecount: $filename" log "Begin processing $count of $filecount: $filename"
log "Checking for audio/subtitle tracks" log "Checking for audio/subtitle tracks"
tracks=$(mkvmerge -J "$video") tracks=$(mkvmerge -J "$video")
if [ ! -z "${tracks}" ]; then if [ ! -z "${tracks}" ]; then
# video tracks # video tracks
VideoTrack=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"video\") | .id") VideoTrack=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"video\") | .id")
VideoTrackCount=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"video\") | .id" | wc -l) VideoTrackCount=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"video\") | .id" | wc -l)
# video preferred language # video preferred language
VideoTrackLanguage=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"video\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id") VideoTrackLanguage=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"video\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id")
# audio tracks # audio tracks
AudioTracks=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"audio\") | .id") AudioTracks=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"audio\") | .id")
AudioTracksCount=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"audio\") | .id" | wc -l) AudioTracksCount=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"audio\") | .id" | wc -l)
# audio preferred language # audio preferred language
AudioTracksLanguage=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id") AudioTracksLanguage=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id")
AudioTracksLanguageCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id" | wc -l) AudioTracksLanguageCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id" | wc -l)
AudioTracksLanguageFound=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"audio\") | .properties.language") AudioTracksLanguageFound=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"audio\") | .properties.language")
# audio unkown laguage # audio unkown laguage
AudioTracksLanguageUND=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"und\")) | .id") AudioTracksLanguageUND=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"und\")) | .id")
AudioTracksLanguageUNDCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"und\")) | .id" | wc -l) AudioTracksLanguageUNDCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==\"und\")) | .id" | wc -l)
AudioTracksLanguageNull=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==null)) | .id") AudioTracksLanguageNull=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==null)) | .id")
AudioTracksLanguageNullCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==null)) | .id" | wc -l) AudioTracksLanguageNullCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language==null)) | .id" | wc -l)
# audio foreign language # audio foreign language
AudioTracksLanguageForeignCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language!=\"${VIDEO_LANG}\")) | .id" | wc -l) AudioTracksLanguageForeignCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"audio\") and select(.properties.language!=\"${VIDEO_LANG}\")) | .id" | wc -l)
# subtitle tracks # subtitle tracks
SubtitleTracks=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"subtitles\") | .id") SubtitleTracks=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"subtitles\") | .id")
SubtitleTracksCount=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"subtitles\") | .id" | wc -l) SubtitleTracksCount=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"subtitles\") | .id" | wc -l)
# subtitle preferred langauge # subtitle preferred langauge
SubtitleTracksLanguage=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"subtitles\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id") SubtitleTracksLanguage=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"subtitles\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id")
SubtitleTracksLanguageCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"subtitles\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id" | wc -l) SubtitleTracksLanguageCount=$(echo "${tracks}" | jq ".tracks[] | select((.type==\"subtitles\") and select(.properties.language==\"${VIDEO_LANG}\")) | .id" | wc -l)
SubtitleTracksLanguageFound=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"subtitles\") | .properties.language") SubtitleTracksLanguageFound=$(echo "${tracks}" | jq ".tracks[] | select(.type==\"subtitles\") | .properties.language")
else else
log "ERROR: ffprobe failed to read tracks and set values" log "ERROR: ffprobe failed to read tracks and set values"
rm "$video" && log "INFO: deleted: $video" rm "$video" && log "INFO: deleted: $video"
fi fi
# Check for video track # Check for video track
if [ -z "${VideoTrack}" ]; then if [ -z "${VideoTrack}" ]; then
log "ERROR: no video track found" log "ERROR: no video track found"
rm "$video" && log "INFO: deleted: $filename" rm "$video" && log "INFO: deleted: $filename"
continue continue
else else
log "$VideoTrackCount video track found!" log "$VideoTrackCount video track found!"
fi fi
# Check for audio track # Check for audio track
if [ -z "${AudioTracks}" ]; then if [ -z "${AudioTracks}" ]; then
log "ERROR: no audio tracks found" log "ERROR: no audio tracks found"
rm "$video" && log "INFO: deleted: $filename" rm "$video" && log "INFO: deleted: $filename"
continue continue
else else
log "$AudioTracksCount audio tracks found!" log "$AudioTracksCount audio tracks found!"
fi fi
# Check for audio track # Check for audio track
if [ ! -z "${SubtitleTracks}" ]; then if [ ! -z "${SubtitleTracks}" ]; then
log "$SubtitleTracksCount subtitle tracks found!" log "$SubtitleTracksCount subtitle tracks found!"
fi fi
if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$SubtitleTracksLanguage" ]; then if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$SubtitleTracksLanguage" ]; then
if [ ${VIDEO_MKVCLEANER} = TRUE ] || [ ${VIDEO_SMA} = TRUE ]; then if [ ${VIDEO_MKVCLEANER} = TRUE ] || [ ${VIDEO_SMA} = TRUE ]; then
if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$SubtitleTracksLanguage" ] || [ ! -z "$AudioTracksLanguageUND" ] || [ ! -z "$AudioTracksLanguageNull" ]; then if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$SubtitleTracksLanguage" ] || [ ! -z "$AudioTracksLanguageUND" ] || [ ! -z "$AudioTracksLanguageNull" ]; then
sleep 0.1 sleep 0.1
else
log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks"
log "ERROR: No \"${VIDEO_LANG}\" or \"Unknown\" audio tracks found..."
log "ERROR: No \"${VIDEO_LANG}\" subtitle tracks found..."
# rm "$video" && echo "INFO: deleted: $filename"
exit 1
continue
fi
else else
log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks" log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks"
log "ERROR: No \"${VIDEO_LANG}\" or \"Unknown\" audio tracks found..." if [ ! -z "${AudioTracks}" ]; then
log "ERROR: No \"${VIDEO_LANG}\" subtitle tracks found..." log "INFO: ${AudioTracksLanguageFound} audio track found!"
fi
if [ ! -z "${SubtitleTracks}" ]; then
log "INFO: ${SubtitleTracksLanguageFound} subtitle track found!"
fi
log "ERROR: No \"${VIDEO_LANG}\" audio or subtitle tracks found..."
# rm "$video" && echo "INFO: deleted: $filename" # rm "$video" && echo "INFO: deleted: $filename"
exit 1 exit 1
continue continue
fi fi
else else
log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks" if [ ! ${VIDEO_MKVCLEANER} = TRUE ] || [ ! ${VIDEO_SMA} = TRUE ]; then
if [ ! -z "${AudioTracks}" ]; then log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks"
log "INFO: ${AudioTracksLanguageFound} audio track found!" if [ ! -z "$AudioTracksLanguage" ]; then
fi log "$AudioTracksLanguageCount \"${VIDEO_LANG}\" audio track found..."
if [ ! -z "${SubtitleTracks}" ]; then fi
log "INFO: ${SubtitleTracksLanguageFound} subtitle track found!" if [ ! -z "$SubtitleTracksLanguage" ]; then
log "$SubtitleTracksLanguageCount \"${VIDEO_LANG}\" subtitle track found..."
fi
fi fi
log "ERROR: No \"${VIDEO_LANG}\" audio or subtitle tracks found..." fi
# rm "$video" && echo "INFO: deleted: $filename"
exit 1 if [ ${VIDEO_MKVCLEANER} = TRUE ]; then
continue log "Begin processing with MKV Cleaner..."
fi
else
if [ ! ${VIDEO_MKVCLEANER} = TRUE ] || [ ! ${VIDEO_SMA} = TRUE ]; then
log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks" log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks"
if [ ! -z "$AudioTracksLanguage" ]; then # Check for unwanted audio tracks and remove/re-label as needed...
log "$AudioTracksLanguageCount \"${VIDEO_LANG}\" audio track found..." if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$AudioTracksLanguageUND" ] || [ ! -z "$AudioTracksLanguageNull" ]; then
fi if [ $AudioTracksCount -ne $AudioTracksLanguageCount ]; then
if [ ! -z "$SubtitleTracksLanguage" ]; then RemoveAudioTracks="true"
log "$SubtitleTracksLanguageCount \"${VIDEO_LANG}\" subtitle track found..." if [ ! -z "$AudioTracksLanguage" ]; then
fi MKVaudio=" -a ${VIDEO_LANG}"
fi log "$AudioTracksLanguageCount audio tracks found!"
fi unwantedaudiocount=$(($AudioTracksCount-$AudioTracksLanguageCount))
if [ $AudioTracksLanguageCount -ne $AudioTracksCount ]; then
if [ ${VIDEO_MKVCLEANER} = TRUE ]; then unwantedaudio="true"
log "Begin processing with MKV Cleaner..." fi
log "Checking for \"${VIDEO_LANG}\" video/audio/subtitle tracks" elif [ ! -z "$AudioTracksLanguageUND" ]; then
# Check for unwanted audio tracks and remove/re-label as needed... for I in $AudioTracksLanguageUND
if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$AudioTracksLanguageUND" ] || [ ! -z "$AudioTracksLanguageNull" ]; then do
if [ $AudioTracksCount -ne $AudioTracksLanguageCount ]; then OUT=$OUT" -a $I --language $I:${VIDEO_LANG}"
RemoveAudioTracks="true" done
if [ ! -z "$AudioTracksLanguage" ]; then MKVaudio="$OUT"
MKVaudio=" -a ${VIDEO_LANG}" log "$AudioTracksLanguageUNDCount \"unknown\" audio tracks found, re-tagging as \"${VIDEO_LANG}\""
log "$AudioTracksLanguageCount audio tracks found!" unwantedaudiocount=$(($AudioTracksCount-$AudioTracksLanguageUNDCount))
unwantedaudiocount=$(($AudioTracksCount-$AudioTracksLanguageCount)) if [ $AudioTracksLanguageUNDCount -ne $AudioTracksCount ]; then
if [ $AudioTracksLanguageCount -ne $AudioTracksCount ]; then unwantedaudio="true"
unwantedaudio="true" fi
fi elif [ ! -z "$AudioTracksLanguageNull" ]; then
elif [ ! -z "$AudioTracksLanguageUND" ]; then for I in $AudioTracksLanguageNull
for I in $AudioTracksLanguageUND do
do OUT=$OUT" -a $I --language $I:${VIDEO_LANG}"
OUT=$OUT" -a $I --language $I:${VIDEO_LANG}" done
done MKVaudio="$OUT"
MKVaudio="$OUT" log "$AudioTracksLanguageNullCount \"unknown\" audio tracks found, re-tagging as \"${VIDEO_LANG}\""
log "$AudioTracksLanguageUNDCount \"unknown\" audio tracks found, re-tagging as \"${VIDEO_LANG}\"" unwantedaudiocount=$(($AudioTracksCount-$AudioTracksLanguageNullCount))
unwantedaudiocount=$(($AudioTracksCount-$AudioTracksLanguageUNDCount)) if [ $AudioTracksLanguageNullCount -ne $AudioTracksCount ]; then
if [ $AudioTracksLanguageUNDCount -ne $AudioTracksCount ]; then unwantedaudio="true"
unwantedaudio="true" fi
fi
elif [ ! -z "$AudioTracksLanguageNull" ]; then
for I in $AudioTracksLanguageNull
do
OUT=$OUT" -a $I --language $I:${VIDEO_LANG}"
done
MKVaudio="$OUT"
log "$AudioTracksLanguageNullCount \"unknown\" audio tracks found, re-tagging as \"${VIDEO_LANG}\""
unwantedaudiocount=$(($AudioTracksCount-$AudioTracksLanguageNullCount))
if [ $AudioTracksLanguageNullCount -ne $AudioTracksCount ]; then
unwantedaudio="true"
fi fi
else
log "$AudioTracksLanguageCount audio tracks found!"
RemoveAudioTracks="false"
MKVaudio=""
fi
elif [ -z "$SubtitleTracksLanguage" ]; then
if [ ! -z "${AudioTracks}" ]; then
log "INFO: ${AudioTracksLanguageFound} audio track found!"
fi
if [ ! -z "${SubtitleTracks}" ]; then
log "INFO: ${SubtitleTracksLanguageFound} subtitle track found!"
fi fi
log "ERROR: no \"${VIDEO_LANG}\" audio/subtitle tracks found!"
# rm "$video" && echo "INFO: deleted: $filename"
exit 1
continue
else else
log "$AudioTracksLanguageCount audio tracks found!" foreignaudio="true"
RemoveAudioTracks="false" RemoveAudioTracks="false"
MKVaudio="" MKVaudio=""
fi fi
elif [ -z "$SubtitleTracksLanguage" ]; then
if [ ! -z "${AudioTracks}" ]; then # Check for unwanted subtitle tracks...
log "INFO: ${AudioTracksLanguageFound} audio track found!" if [ ! -z "$SubtitleTracks" ]; then
fi if [ $SubtitleTracksCount -ne $SubtitleTracksLanguageCount ]; then
if [ ! -z "${SubtitleTracks}" ]; then RemoveSubtitleTracks="true"
log "INFO: ${SubtitleTracksLanguageFound} subtitle track found!" MKVSubtitle=" -s ${VIDEO_LANG}"
fi if [ ! -z "$SubtitleTracksLanguage" ]; then
log "ERROR: no \"${VIDEO_LANG}\" audio/subtitle tracks found!" log "$SubtitleTracksLanguageCount subtitle tracks found!"
# rm "$video" && echo "INFO: deleted: $filename" fi
exit 1 unwantedsubtitlecount=$(($SubtitleTracksCount-$SubtitleTracksLanguageCount))
continue if [ $SubtitleTracksLanguageCount -ne $SubtitleTracksCount ]; then
else unwantedsubtitle="true"
foreignaudio="true" fi
RemoveAudioTracks="false" else
MKVaudio=""
fi
# Check for unwanted subtitle tracks...
if [ ! -z "$SubtitleTracks" ]; then
if [ $SubtitleTracksCount -ne $SubtitleTracksLanguageCount ]; then
RemoveSubtitleTracks="true"
MKVSubtitle=" -s ${VIDEO_LANG}"
if [ ! -z "$SubtitleTracksLanguage" ]; then
log "$SubtitleTracksLanguageCount subtitle tracks found!" log "$SubtitleTracksLanguageCount subtitle tracks found!"
fi RemoveSubtitleTracks="false"
unwantedsubtitlecount=$(($SubtitleTracksCount-$SubtitleTracksLanguageCount)) MKVSubtitle=""
if [ $SubtitleTracksLanguageCount -ne $SubtitleTracksCount ]; then
unwantedsubtitle="true"
fi fi
else else
log "$SubtitleTracksLanguageCount subtitle tracks found!"
RemoveSubtitleTracks="false" RemoveSubtitleTracks="false"
MKVSubtitle="" MKVSubtitle=""
fi fi
else
RemoveSubtitleTracks="false" # Correct video language, if needed...
MKVSubtitle="" if [ -z "$VideoTrackLanguage" ]; then
fi if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$AudioTracksLanguageUND" ] || [ ! -z "$AudioTracksLanguageNull" ]; then
SetVideoLanguage="true"
# Correct video language, if needed... if [ "${RemoveAudioTracks}" = true ] || [ "${RemoveSubtitleTracks}" = true ]; then
if [ -z "$VideoTrackLanguage" ]; then log "$VideoTrackCount \"unknown\" video language track found, re-tagging as \"${VIDEO_LANG}\""
if [ ! -z "$AudioTracksLanguage" ] || [ ! -z "$AudioTracksLanguageUND" ] || [ ! -z "$AudioTracksLanguageNull" ]; then fi
SetVideoLanguage="true" MKVvideo=" -d ${VideoTrack} --language ${VideoTrack}:${VIDEO_LANG}"
if [ "${RemoveAudioTracks}" = true ] || [ "${RemoveSubtitleTracks}" = true ]; then else
log "$VideoTrackCount \"unknown\" video language track found, re-tagging as \"${VIDEO_LANG}\"" foreignvideo="true"
SetVideoLanguage="false"
MKVvideo=""
fi fi
MKVvideo=" -d ${VideoTrack} --language ${VideoTrack}:${VIDEO_LANG}"
else else
foreignvideo="true" log "$VideoTrackCount video track found!"
SetVideoLanguage="false" SetVideoLanguage="false"
MKVvideo="" MKVvideo=""
fi fi
else
log "$VideoTrackCount video track found!" # Display foreign audio track counts
SetVideoLanguage="false" if [ "$foreignaudio" = true ] || [ "$foreignvideo" = true ]; then
MKVvideo="" log "Checking for \"foreign\" audio/video tracks"
fi if [ "$foreignvideo" = true ]; then
log "$VideoTrackCount video track found!"
# Display foreign audio track counts foreignvideo="false"
if [ "$foreignaudio" = true ] || [ "$foreignvideo" = true ]; then fi
log "Checking for \"foreign\" audio/video tracks" if [ "$foreignaudio" = true ]; then
if [ "$foreignvideo" = true ]; then log "$AudioTracksLanguageForeignCount audio tracks found!"
log "$VideoTrackCount video track found!" foreignaudio="false"
foreignvideo="false" fi
fi
if [ "$foreignaudio" = true ]; then
log "$AudioTracksLanguageForeignCount audio tracks found!"
foreignaudio="false"
fi fi
fi
# Display unwanted audio/subtitle track counts
# Display unwanted audio/subtitle track counts if [ "$unwantedaudio" = true ] || [ "$unwantedsubtitle" = true ]; then
if [ "$unwantedaudio" = true ] || [ "$unwantedsubtitle" = true ]; then log "Checking for unwanted \"not: ${VIDEO_LANG}\" audio/subtitle tracks"
log "Checking for unwanted \"not: ${VIDEO_LANG}\" audio/subtitle tracks" if [ "$unwantedaudio" = true ]; then
if [ "$unwantedaudio" = true ]; then log "$unwantedaudiocount audio tracks to remove..."
log "$unwantedaudiocount audio tracks to remove..." unwantedaudio="false"
unwantedaudio="false" fi
if [ "$unwantedsubtitle" = true ]; then
log "$unwantedsubtitlecount subtitle tracks to remove..."
unwantedsubtitle="false"
fi
fi fi
if [ "$unwantedsubtitle" = true ]; then skip="false"
log "$unwantedsubtitlecount subtitle tracks to remove..." if [ "${RemoveAudioTracks}" = false ] && [ "${RemoveSubtitleTracks}" = false ]; then
unwantedsubtitle="false" if find "$video" -type f -iname "*.mkv" | read; then
log "INFO: Video passed all checks, no processing needed"
touch "$video"
if [ ${VIDEO_SMA} = TRUE ]; then
skip="true"
fi
else
log "INFO: Video passed all checks, but is in the incorrect container, repackaging as mkv..."
MKVvideo=" -d ${VideoTrack} --language ${VideoTrack}:${VIDEO_LANG}"
MKVaudio=" -a ${VIDEO_LANG}"
MKVSubtitle=" -s ${VIDEO_LANG}"
fi
fi fi
fi if [ $skip = false ]; then
skip="false" if mkvmerge --no-global-tags --title "" -o "${basefilename}.merged.mkv"${MKVvideo}${MKVaudio}${MKVSubtitle} "$video"; then
if [ "${RemoveAudioTracks}" = false ] && [ "${RemoveSubtitleTracks}" = false ]; then log "SUCCESS: mkvmerge complete"
if find "$video" -type f -iname "*.mkv" | read; then log "INFO: Options used:${MKVvideo}${MKVaudio}${MKVSubtitle}"
log "INFO: Video passed all checks, no processing needed" # cleanup temp files and rename
touch "$video" mv "$video" "$video.original" && log "INFO: Renamed source file"
if [ ${VIDEO_SMA} = TRUE ]; then mv "${basefilename}.merged.mkv" "${basefilename}.mkv" && log "INFO: Renamed temp file"
skip="true" rm "$video.original" && log "INFO: Deleted source file"
extension="mkv"
else
log "ERROR: mkvmerge failed"
rm "$video" && log "INFO: deleted: $video"
rm "${basefilename}.merged.mkv" && log "INFO: deleted: ${basefilename}.merged.mkv"
continue
fi fi
else
log "INFO: Video passed all checks, but is in the incorrect container, repackaging as mkv..."
MKVvideo=" -d ${VideoTrack} --language ${VideoTrack}:${VIDEO_LANG}"
MKVaudio=" -a ${VIDEO_LANG}"
MKVSubtitle=" -s ${VIDEO_LANG}"
fi fi
fi fi
if [ $skip = false ]; then
if mkvmerge --no-global-tags --title "" -o "${basefilename}.merged.mkv"${MKVvideo}${MKVaudio}${MKVSubtitle} "$video"; then if [ "${extension}" == "mkv" ]; then
log "SUCCESS: mkvmerge complete" log "========================START MKVPROPEDIT========================"
log "INFO: Options used:${MKVvideo}${MKVaudio}${MKVSubtitle}" mkvpropedit "${basefilename}.${extension}" --add-track-statistics-tags
# cleanup temp files and rename log "========================STOP MKVPROPEDIT========================="
mv "$video" "$video.original" && log "INFO: Renamed source file"
mv "${basefilename}.merged.mkv" "${basefilename}.mkv" && log "INFO: Renamed temp file"
rm "$video.original" && log "INFO: Deleted source file"
extension="mkv"
else
log "ERROR: mkvmerge failed"
rm "$video" && log "INFO: deleted: $video"
rm "${basefilename}.merged.mkv" && log "INFO: deleted: ${basefilename}.merged.mkv"
continue
fi
fi fi
fi
if [ ${VIDEO_SMA} = TRUE ]; then
if [ "${extension}" == "mkv" ]; then if [ -f "${basefilename}.${extension}" ]; then
log "========================START MKVPROPEDIT========================" log ""
mkvpropedit "${basefilename}.${extension}" --add-track-statistics-tags log "Begin processing with Sickbeard MP4 Automator..."
log "========================STOP MKVPROPEDIT=========================" log ""
fi # Manual run of Sickbeard MP4 Automator
if python3 /usr/local/sma/manual.py --config "/config/scripts/configs/$5-sma.ini" -i "${basefilename}.${extension}" $tagging; then
if [ ${VIDEO_SMA} = TRUE ]; then log "Processing complete for: ${filename}!"
if [ -f "${basefilename}.${extension}" ]; then else
log "" log "ERROR: Sickbeard MP4 Automator Processing Error"
log "Begin processing with Sickbeard MP4 Automator..." rm "$video" && log "INFO: deleted: $filename"
log "" fi
# Manual run of Sickbeard MP4 Automator
if python3 /usr/local/sma/manual.py --config "/config/scripts/configs/$5-sma.ini" -i "${basefilename}.${extension}" $tagging; then
log "Processing complete for: ${filename}!"
else
log "ERROR: Sickbeard MP4 Automator Processing Error"
rm "$video" && log "INFO: deleted: $filename"
fi fi
fi fi
fi log "===================================================="
log "====================================================" done
done
if [ ${VIDEO_SMA} = TRUE ] || [ ${VIDEO_MKVCLEANER} = TRUE ]; then if [ ${VIDEO_SMA} = TRUE ] || [ ${VIDEO_MKVCLEANER} = TRUE ]; then
find "$1" -type f ! -newer "$1/sma-conversion-check" ! -name "sma-conversion-check" -delete find "$1" -type f ! -newer "$1/sma-conversion-check" ! -name "sma-conversion-check" -delete
# check for video files # check for video files
if find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\)" | read; then if find "$1" -type f -iregex ".*/.*\.\(mkv\|mp4\)" | read; then
log "Post Processing Complete!" log "Post Processing Complete!"
else else
log "ERROR: Post Processing failed, no video files found..." log "ERROR: Post Processing failed, no video files found..."
exit 1 exit 1
fi fi
if [ -f "$1/sma-conversion-check" ]; then if [ -f "$1/sma-conversion-check" ]; then
rm "$1/sma-conversion-check" rm "$1/sma-conversion-check"
fi
fi fi
fi }
Main "$@" | tee -a /config/scripts/logs/video-pp.log
chmod 666 /config/scripts/logs/video-pp.log
chown abc:abc /config/scripts/logs/video-pp.log
exit $? exit $?

Loading…
Cancel
Save