v1.0.25 - Use functions for various processes

Simplify code...
master
RandomNinjaAtk 2 years ago committed by GitHub
parent d423da4a36
commit f633b87914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,7 @@
export LC_ALL=C.UTF-8 export LC_ALL=C.UTF-8
export LANG=C.UTF-8 export LANG=C.UTF-8
TITLESHORT="VPP" TITLESHORT="VPP"
scriptVersion=1.0.24 scriptVersion=1.0.25
set -e set -e
set -o pipefail set -o pipefail
@ -52,23 +52,7 @@ function log {
echo $m_time" :: $scriptVersion :: "$1 echo $m_time" :: $scriptVersion :: "$1
} }
VideoLanguageCheck () {
function Main {
SECONDS=0
error=0
folderpath="$1"
jobname="$3"
category="$5"
Configuration
# check for video files
if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then
sleep 0.1
else
log "ERROR: No video files found for processing"
exit 1
fi
count=0 count=0
fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l) fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
@ -114,53 +98,15 @@ function Main {
fi fi
fi fi
log "$count of $fileCount :: Processing complete for: ${fileName}!"
done
# check for video files
if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then
sleep 0.1
else
log "ERROR: No video files found for processing"
exit 1
fi
if [ ${VIDEO_SMA} = TRUE ]; then log "$count of $fileCount :: Processing complete for: ${fileName}!"
count=0
fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
log "Processing ${fileCount} video files..."
find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" -print0 | while IFS= read -r -d '' file; do
count=$(($count+1))
baseFileName="${file%.*}"
fileName="$(basename "$file")"
extension="${fileName##*.}"
log "$count of $fileCount :: Processing $fileName"
if [ -f "$file" ]; then
if [ -f /usr/local/sma/config/sma.log ]; then
rm /usr/local/sma/config/sma.log
fi
log "$count of $fileCount :: Processing with SMA..."
if [ -f "/config/scripts/configs/$5-sma.ini" ]; then
# Manual run of Sickbeard MP4 Automator
if python3 /usr/local/sma/manual.py --config "/config/scripts/configs/$5-sma.ini" -i "$file" $tagging; then
log "$count of $fileCount :: Complete!"
else
log "$count of $fileCount :: ERROR :: SMA Processing Error"
rm "$file" && log "INFO: deleted: $fileName"
fi
else
log "$count of $fileCount :: ERROR :: SMA Processing Error"
log "$count of $fileCount :: ERROR :: \"/config/scripts/configs/$5-sma.ini\" configuration file is missing..."
rm "$file" && log "INFO: deleted: $fileName"
fi
fi
done done
fi
}
VideoFileCheck () {
# check for video files # check for video files
if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then
sleep 0.1 sleep 0.1
@ -168,7 +114,9 @@ function Main {
log "ERROR: No video files found for processing" log "ERROR: No video files found for processing"
exit 1 exit 1
fi fi
}
VideoSmaProcess (){
count=0 count=0
fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l) fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
log "Processing ${fileCount} video files..." log "Processing ${fileCount} video files..."
@ -178,54 +126,48 @@ function Main {
fileName="$(basename "$file")" fileName="$(basename "$file")"
extension="${fileName##*.}" extension="${fileName##*.}"
log "$count of $fileCount :: Processing $fileName" log "$count of $fileCount :: Processing $fileName"
videoData=$(ffprobe -v quiet -print_format json -show_streams "$file") if [ -f "$file" ]; then
videoAudioTracksCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"audio\") | .index" | wc -l) if [ -f /usr/local/sma/config/sma.log ]; then
videoSubtitleTracksCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"subtitle\") | .index" | wc -l) rm /usr/local/sma/config/sma.log
log "$count of $fileCount :: $videoAudioTracksCount Audio Tracks Found!"
log "$count of $fileCount :: $videoSubtitleTracksCount Subtitle Tracks Found!"
videoAudioLanguages=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"audio\") | .tags.language")
videoSubtitleLanguages=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"subtitle\") | .tags.language")
# Language Check
log "$count of $fileCount :: Checking for preferred languages \"$VIDEO_LANG\""
preferredLanguage=false
IFS=',' read -r -a filters <<< "$VIDEO_LANG"
for filter in "${filters[@]}"
do
videoAudioTracksLanguageCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"audio\") | select(.tags.language==\"${filter}\") | .index" | wc -l)
videoSubtitleTracksLanguageCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"subtitle\") | select(.tags.language==\"${filter}\") | .index" | wc -l)
log "$count of $fileCount :: $videoAudioTracksLanguageCount \"$filter\" Audio Tracks Found!"
log "$count of $fileCount :: $videoSubtitleTracksLanguageCount \"$filter\" Subtitle Tracks Found!"
if [ "$preferredLanguage" == "false" ]; then
if echo "$videoAudioLanguages" | grep -i "$filter" | read; then
preferredLanguage=true
elif echo "$videoSubtitleLanguages" | grep -i "$filter" | read; then
preferredLanguage=true
fi
fi fi
done log "$count of $fileCount :: Processing with SMA..."
if [ -f "/config/scripts/configs/$2-sma.ini" ]; then
if [ "$preferredLanguage" == "false" ]; then
if [ "$RequireLanguage" == "true" ]; then # Manual run of Sickbeard MP4 Automator
log "$count of $fileCount :: ERROR :: No matching languages found in $(($videoAudioTracksCount + $videoSubtitleTracksCount)) Audio/Subtitle tracks" if python3 /usr/local/sma/manual.py --config "/config/scripts/configs/$2-sma.ini" -i "$file" $tagging; then
log "$count of $fileCount :: ERROR :: Disable " log "$count of $fileCount :: Complete!"
else
log "$count of $fileCount :: ERROR :: SMA Processing Error"
rm "$file" && log "INFO: deleted: $fileName"
fi
else
log "$count of $fileCount :: ERROR :: SMA Processing Error"
log "$count of $fileCount :: ERROR :: \"/config/scripts/configs/$2-sma.ini\" configuration file is missing..."
rm "$file" && log "INFO: deleted: $fileName" rm "$file" && log "INFO: deleted: $fileName"
fi fi
fi fi
log "$count of $fileCount :: Processing complete for: ${fileName}!"
done done
}
if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then function Main {
duration=$SECONDS SECONDS=0
echo "Post Processing Completed in $(($duration / 60 )) minutes and $(($duration % 60 )) seconds!" error=0
else folderpath="$1"
log "ERROR :: Post Processing failed, no video files found..." jobname="$3"
exit 1 category="$5"
fi
Configuration
VideoFileCheck "$folderpath"
VideoLanguageCheck "$folderpath"
VideoFileCheck "$folderpath"
VideoSmaProcess "$folderpath" "$category"
VideoFileCheck "$folderpath"
VideoLanguageCheck "$folderpath"
VideoFileCheck "$folderpath"
duration=$SECONDS
echo "Post Processing Completed in $(($duration / 60 )) minutes and $(($duration % 60 )) seconds!"
} }
Main "$@" Main "$@"

Loading…
Cancel
Save