Update video.bash

This commit is contained in:
RandomNinjaAtk 2023-07-07 08:57:15 -04:00 committed by GitHub
parent e49b1b1ad9
commit 311d22aa85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,13 +1,16 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
export LC_ALL=C.UTF-8 scriptVersion="1.0.0"
export LANG=C.UTF-8
TITLESHORT="VPP"
scriptVersion=1.0.0
set -e set -e
set -o pipefail set -o pipefail
######## Settings
videoLanguages="eng"
requireLanguageMatch="true"
enableSma="true"
enableSmaTagging="true"
######## Package dependencies installation
InstallRequirements () { InstallRequirements () {
if [ ! -f "/config/logs/video.txt" ]; then if [ ! -f "/config/logs/video.txt" ]; then
echo "Installing Required Packages..." echo "Installing Required Packages..."
@ -33,30 +36,32 @@ InstallRequirements () {
fi fi
} }
# auto-clean up log file to reduce space usage
if [ -f "/config/scripts/video.txt" ]; then
find /config/scripts -type f -name "video.txt" -size +1024k -delete
fi
touch "/config/logs/video.txt"
chmod 666 "/config/logs/video.txt" touch "/config/scripts/video.txt"
exec &> >(tee -a "/config/logs/video.txt") chmod 666 "/config/scripts/video.txt"
exec &> >(tee -a "/config/scripts/video.txt")
function Configuration { function Configuration {
log "SABnzbd Job: $jobname" log "SABnzbd Job: $jobname"
log "SABnzbd Category: $category" log "SABnzbd Category: $category"
log "DOCKER: $TITLE" log "Script Versiion: $scriptVersion"
log "SCRIPT VERSION: $scriptVersion"
log "SCRIPT: Video Post Processor ($TITLESHORT)"
log "CONFIGURATION VERIFICATION" log "CONFIGURATION VERIFICATION"
log "##########################" log "##########################"
log "Preferred Audio/Subtitle Languages: ${videoLanguages}"
log "Preferred Audio/Subtitle Languages: ${VIDEO_LANG}" if [ "${requireLanguageMatch}" = "true" ]; then
if [ "${RequireLanguage}" = "true" ]; then
log "Require Matching Language :: Enabled" log "Require Matching Language :: Enabled"
else else
log "Require Matching Language :: Disabled" log "Require Matching Language :: Disabled"
fi fi
if [ ${VIDEO_SMA} = TRUE ]; then if [ ${enableSma} = true ]; then
log "$TITLESHORT: Sickbeard MP4 Automator (SMA): ENABLED" log "Sickbeard MP4 Automator (SMA): ENABLED"
if [ ${VIDEO_SMA_TAGGING} = TRUE ]; then if [ ${enableSmaTagging} = true ]; then
tagging="-a" tagging="-a"
log "Sickbeard MP4 Automator (SMA): Tagging: ENABLED" log "Sickbeard MP4 Automator (SMA): Tagging: ENABLED"
else else
@ -67,8 +72,8 @@ function Configuration {
log "Sickbeard MP4 Automator (SMA): DISABLED" log "Sickbeard MP4 Automator (SMA): DISABLED"
fi fi
if [ -z "VIDEO_SMA_TAGGING" ]; then if [ -z "enableSmaTagging" ]; then
VIDEO_SMA_TAGGING=FALSE enableSmaTagging=FALSE
fi fi
} }
@ -98,9 +103,9 @@ VideoLanguageCheck () {
videoSubtitleLanguages=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"subtitle\") | .tags.language") videoSubtitleLanguages=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"subtitle\") | .tags.language")
# Language Check # Language Check
log "$count of $fileCount :: Checking for preferred languages \"$VIDEO_LANG\"" log "$count of $fileCount :: Checking for preferred languages \"$videoLanguages\""
preferredLanguage=false preferredLanguage=false
IFS=',' read -r -a filters <<< "$VIDEO_LANG" IFS=',' read -r -a filters <<< "$videoLanguages"
for filter in "${filters[@]}" for filter in "${filters[@]}"
do do
videoAudioTracksLanguageCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"audio\") | select(.tags.language==\"${filter}\") | .index" | wc -l) videoAudioTracksLanguageCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"audio\") | select(.tags.language==\"${filter}\") | .index" | wc -l)
@ -117,12 +122,12 @@ VideoLanguageCheck () {
done done
if [ "$preferredLanguage" == "false" ]; then if [ "$preferredLanguage" == "false" ]; then
if [ ${VIDEO_SMA} = TRUE ]; then if [ ${enableSma} = true ]; then
if [ "$smaProcessComplete" == "false" ]; then if [ "$smaProcessComplete" == "false" ]; then
return return
fi fi
fi fi
if [ "$RequireLanguage" == "true" ]; then if [ "$requireLanguageMatch" == "true" ]; then
log "$count of $fileCount :: ERROR :: No matching languages found in $(($videoAudioTracksCount + $videoSubtitleTracksCount)) Audio/Subtitle tracks" log "$count of $fileCount :: ERROR :: No matching languages found in $(($videoAudioTracksCount + $videoSubtitleTracksCount)) Audio/Subtitle tracks"
log "$count of $fileCount :: ERROR :: Disable " log "$count of $fileCount :: ERROR :: Disable "
rm "$file" && log "INFO: deleted: $fileName" rm "$file" && log "INFO: deleted: $fileName"
@ -162,10 +167,10 @@ VideoSmaProcess (){
rm /usr/local/sma/config/sma.log rm /usr/local/sma/config/sma.log
fi fi
log "$count of $fileCount :: Processing with SMA..." log "$count of $fileCount :: Processing with SMA..."
if [ -f "/config/$2-sma.ini" ]; then if [ -f "/config/scripts/sma.ini" ]; then
# Manual run of Sickbeard MP4 Automator # Manual run of Sickbeard MP4 Automator
if python3 /usr/local/sma/manual.py --config "/config/$2-sma.ini" -i "$file" $tagging; then if python3 /usr/local/sma/manual.py --config "/config/scripts/sma.ini" -i "$file" $tagging; then
log "$count of $fileCount :: Complete!" log "$count of $fileCount :: Complete!"
else else
log "$count of $fileCount :: ERROR :: SMA Processing Error" log "$count of $fileCount :: ERROR :: SMA Processing Error"
@ -173,7 +178,7 @@ VideoSmaProcess (){
fi fi
else else
log "$count of $fileCount :: ERROR :: SMA Processing Error" log "$count of $fileCount :: ERROR :: SMA Processing Error"
log "$count of $fileCount :: ERROR :: \"/config/$2-sma.ini\" configuration file is missing..." log "$count of $fileCount :: ERROR :: \"/config/scripts/sma.ini\" configuration file is missing..."
rm "$file" && log "INFO: deleted: $fileName" rm "$file" && log "INFO: deleted: $fileName"
fi fi
fi fi
@ -193,7 +198,7 @@ function Main {
VideoFileCheck "$folderpath" VideoFileCheck "$folderpath"
VideoLanguageCheck "$folderpath" VideoLanguageCheck "$folderpath"
VideoFileCheck "$folderpath" VideoFileCheck "$folderpath"
if [ ${VIDEO_SMA} = TRUE ]; then if [ ${enableSma} = true ]; then
VideoSmaProcess "$folderpath" "$category" VideoSmaProcess "$folderpath" "$category"
fi fi
VideoFileCheck "$folderpath" VideoFileCheck "$folderpath"