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 LANG=C.UTF-8
TITLESHORT="VPP"
scriptVersion=1.0.24
scriptVersion=1.0.25
set -e
set -o pipefail
@ -52,23 +52,7 @@ function log {
echo $m_time" :: $scriptVersion :: "$1
}
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
VideoLanguageCheck () {
count=0
fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
@ -114,53 +98,15 @@ function Main {
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
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
log "$count of $fileCount :: Processing complete for: ${fileName}!"
done
fi
done
}
VideoFileCheck () {
# check for video files
if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then
sleep 0.1
@ -168,7 +114,9 @@ function Main {
log "ERROR: No video files found for processing"
exit 1
fi
}
VideoSmaProcess (){
count=0
fileCount=$(find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | wc -l)
log "Processing ${fileCount} video files..."
@ -178,54 +126,48 @@ function Main {
fileName="$(basename "$file")"
extension="${fileName##*.}"
log "$count of $fileCount :: Processing $fileName"
videoData=$(ffprobe -v quiet -print_format json -show_streams "$file")
videoAudioTracksCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"audio\") | .index" | wc -l)
videoSubtitleTracksCount=$(echo "${videoData}" | jq -r ".streams[] | select(.codec_type==\"subtitle\") | .index" | wc -l)
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
if [ -f "$file" ]; then
if [ -f /usr/local/sma/config/sma.log ]; then
rm /usr/local/sma/config/sma.log
fi
done
if [ "$preferredLanguage" == "false" ]; then
if [ "$RequireLanguage" == "true" ]; then
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 :: Processing with SMA..."
if [ -f "/config/scripts/configs/$2-sma.ini" ]; then
# Manual run of Sickbeard MP4 Automator
if python3 /usr/local/sma/manual.py --config "/config/scripts/configs/$2-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/$2-sma.ini\" configuration file is missing..."
rm "$file" && log "INFO: deleted: $fileName"
fi
fi
log "$count of $fileCount :: Processing complete for: ${fileName}!"
done
}
if find "$1" -type f -regex ".*/.*\.\(m4v\|wmv\|mkv\|mp4\|avi\)" | read; then
duration=$SECONDS
echo "Post Processing Completed in $(($duration / 60 )) minutes and $(($duration % 60 )) seconds!"
else
log "ERROR :: Post Processing failed, no video files found..."
exit 1
fi
function Main {
SECONDS=0
error=0
folderpath="$1"
jobname="$3"
category="$5"
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 "$@"

Loading…
Cancel
Save