handbrake_for_plex.sh
-shellcheck script
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
italic="\033[3m"
|
italic="\033[3m"
|
||||||
underline="\033[4m"
|
#underline="\033[4m"
|
||||||
ita_under="\033[3;4m"
|
#ita_under="\033[3;4m"
|
||||||
bgd="\033[1;4;31m"
|
#bgd="\033[1;4;31m"
|
||||||
red="\033[1;31m"
|
red="\033[1;31m"
|
||||||
green="\033[1;32m"
|
green="\033[1;32m"
|
||||||
yellow="\033[1;33m"
|
yellow="\033[1;33m"
|
||||||
bold="\033[1m"
|
bold="\033[1m"
|
||||||
box="\033[1;41m"
|
#box="\033[1;41m"
|
||||||
reset="\033[0m"
|
reset="\033[0m"
|
||||||
|
|
||||||
shopt -s globstar
|
shopt -s globstar
|
||||||
@@ -45,25 +45,22 @@ showHelp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notification() {
|
notification() {
|
||||||
#path_img=`dirname "$0"`
|
#path_img=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
path_img=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
||||||
|
|
||||||
if [ $3 -eq 0 ];
|
if [ "$3" -eq 0 ];
|
||||||
then
|
then
|
||||||
sound="Glass"
|
sound="Glass"
|
||||||
#message="Envoi terminé sur $2 !"
|
#image="$path_img/success.png"
|
||||||
image="$path_img/success.png"
|
|
||||||
#image="$path_img/HandBrake.icns"
|
#image="$path_img/HandBrake.icns"
|
||||||
else
|
else
|
||||||
sound="Basso"
|
sound="Basso"
|
||||||
#message="Echec lors de l'envoi sur $2"
|
#image="$path_img/error.png"
|
||||||
image="$path_img/error.png"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v zenity)" ]; then
|
if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v zenity)" ]; then
|
||||||
zenity --title="$1" --notification --text="$2"
|
zenity --title="$1" --notification --text="$2"
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then
|
elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then
|
||||||
# -appIcon ne marche avec BigSur
|
### -appIcon ne marche avec BigSur
|
||||||
# terminal-notifier -title "$1" -message "$2" -sound "$sound" -contentImage "$image" -activate "com.colliderli.iina"
|
# terminal-notifier -title "$1" -message "$2" -sound "$sound" -contentImage "$image" -activate "com.colliderli.iina"
|
||||||
terminal-notifier -title "$1" -message "$2" -sound "$sound" -appIcon "https://sur-le-sentier.fr/HandBrake.png" -activate "com.colliderli.iina"
|
terminal-notifier -title "$1" -message "$2" -sound "$sound" -appIcon "https://sur-le-sentier.fr/HandBrake.png" -activate "com.colliderli.iina"
|
||||||
# org.galad.Subler.plist com.colliderli.iina.plist -appIcon http://vjeantet.fr/images/logo.png
|
# org.galad.Subler.plist com.colliderli.iina.plist -appIcon http://vjeantet.fr/images/logo.png
|
||||||
@@ -91,7 +88,7 @@ shift $((OPTIND-1))
|
|||||||
|
|
||||||
# https://stackoverflow.com/questions/59895/how-can-i-get-the-directory-where-a-bash-script-is-located-from-within-the-scrip
|
# https://stackoverflow.com/questions/59895/how-can-i-get-the-directory-where-a-bash-script-is-located-from-within-the-scrip
|
||||||
#DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
#DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
|
||||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
#SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
#DIR_SCRIPT=$(dirname -- "$( readlink -f -- "$0"; )")
|
#DIR_SCRIPT=$(dirname -- "$( readlink -f -- "$0"; )")
|
||||||
|
|
||||||
####
|
####
|
||||||
@@ -167,7 +164,7 @@ REGEX2="[0-9]{4}"
|
|||||||
for FILE in "${SRC}"/**/*.{mkv,avi,mp4,m4v}
|
for FILE in "${SRC}"/**/*.{mkv,avi,mp4,m4v}
|
||||||
do
|
do
|
||||||
filename=$(basename "$FILE")
|
filename=$(basename "$FILE")
|
||||||
extension=${filename##*.}
|
#extension=${filename##*.}
|
||||||
filename=${filename%.*}
|
filename=${filename%.*}
|
||||||
|
|
||||||
# Get file size
|
# Get file size
|
||||||
@@ -207,7 +204,7 @@ END_COMMENT
|
|||||||
infos=$(mediainfo "$FILE" --output=JSON | jq -s 'map({ VideoCount: .media.track[0].VideoCount, AudioCount: .media.track[0].AudioCount, TextCount: .media.track[0].TextCount, MenuCount: .media.track[0].MenuCount, FormatFichier: .media.track[0].Format, FileSize: .media.track[0].FileSize, Duration: .media.track[0].Duration, FormatVideo: .media.track[1].Format, Format_Profile: .media.track[1].Format_Profile, Format_Level: .media.track[1].Format_Level, "CodecVideo": .media.track[1].CodecID, Width: .media.track[1].Width, Height: .media.track[1].Height, FormatAudio: .media.track[2].Format, FormatAdditionalFeatures: .media.track[2].Format_AdditionalFeatures, CodecAudio: .media.track[2].CodecID, TitleAudio: .media.track[2].Title, LanguageAudio: .media.track[2].Language, DefaultAudio: .media.track[2].Default, FormatText: .media.track[3].Format, CodecText: .media.track[3].CodecID, LanguageText: .media.track[3].Language, DefaultText: .media.track[3].Default, Menu: .media.track[4].extra})')
|
infos=$(mediainfo "$FILE" --output=JSON | jq -s 'map({ VideoCount: .media.track[0].VideoCount, AudioCount: .media.track[0].AudioCount, TextCount: .media.track[0].TextCount, MenuCount: .media.track[0].MenuCount, FormatFichier: .media.track[0].Format, FileSize: .media.track[0].FileSize, Duration: .media.track[0].Duration, FormatVideo: .media.track[1].Format, Format_Profile: .media.track[1].Format_Profile, Format_Level: .media.track[1].Format_Level, "CodecVideo": .media.track[1].CodecID, Width: .media.track[1].Width, Height: .media.track[1].Height, FormatAudio: .media.track[2].Format, FormatAdditionalFeatures: .media.track[2].Format_AdditionalFeatures, CodecAudio: .media.track[2].CodecID, TitleAudio: .media.track[2].Title, LanguageAudio: .media.track[2].Language, DefaultAudio: .media.track[2].Default, FormatText: .media.track[3].Format, CodecText: .media.track[3].CodecID, LanguageText: .media.track[3].Language, DefaultText: .media.track[3].Default, Menu: .media.track[4].extra})')
|
||||||
|
|
||||||
# General
|
# General
|
||||||
nb_video=$(echo "$infos" | jq -j '.[] | .VideoCount')
|
#nb_video=$(echo "$infos" | jq -j '.[] | .VideoCount')
|
||||||
nb_audio=$(echo "$infos" | jq -j '.[] | .AudioCount')
|
nb_audio=$(echo "$infos" | jq -j '.[] | .AudioCount')
|
||||||
if [[ "$nb_audio" == "null" ]]; then nb_audio=0; fi
|
if [[ "$nb_audio" == "null" ]]; then nb_audio=0; fi
|
||||||
nb_text=$(echo "$infos" | jq -j '.[] | .TextCount')
|
nb_text=$(echo "$infos" | jq -j '.[] | .TextCount')
|
||||||
@@ -218,6 +215,7 @@ END_COMMENT
|
|||||||
filesize=$(echo "$infos" | jq -j '.[] | .FileSize' | numfmt --to=si --format "%8.2f" | xargs)
|
filesize=$(echo "$infos" | jq -j '.[] | .FileSize' | numfmt --to=si --format "%8.2f" | xargs)
|
||||||
#fsize=$(numfmt --to iec --format "%8.2f" "$filesize")
|
#fsize=$(numfmt --to iec --format "%8.2f" "$filesize")
|
||||||
duree=$(echo "$infos" | jq -j '.[] | .Duration' | awk -F "." '{print $1}' | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}' | xargs)
|
duree=$(echo "$infos" | jq -j '.[] | .Duration' | awk -F "." '{print $1}' | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}' | xargs)
|
||||||
|
|
||||||
# Video
|
# Video
|
||||||
format_video=$(echo "$infos" | jq -j '.[] | .FormatVideo')
|
format_video=$(echo "$infos" | jq -j '.[] | .FormatVideo')
|
||||||
format_profile=$(echo "$infos" | jq -j '.[] | .Format_Profile')
|
format_profile=$(echo "$infos" | jq -j '.[] | .Format_Profile')
|
||||||
@@ -225,6 +223,7 @@ END_COMMENT
|
|||||||
codec_video=$(echo "$infos" | jq -j '.[] | .CodecVideo')
|
codec_video=$(echo "$infos" | jq -j '.[] | .CodecVideo')
|
||||||
width=$(echo "$infos" | jq -j '.[] | .Width')
|
width=$(echo "$infos" | jq -j '.[] | .Width')
|
||||||
height=$(echo "$infos" | jq -j '.[] | .Height')
|
height=$(echo "$infos" | jq -j '.[] | .Height')
|
||||||
|
|
||||||
# Audio
|
# Audio
|
||||||
format_audio=$(echo "$infos" | jq -j '.[] | .FormatAudio')
|
format_audio=$(echo "$infos" | jq -j '.[] | .FormatAudio')
|
||||||
format_addition=$(echo "$infos" | jq -j '.[] | .FormatAdditionalFeatures')
|
format_addition=$(echo "$infos" | jq -j '.[] | .FormatAdditionalFeatures')
|
||||||
@@ -235,11 +234,13 @@ END_COMMENT
|
|||||||
if [[ "$language_audio" == "null" ]]; then language_audio=""; fi
|
if [[ "$language_audio" == "null" ]]; then language_audio=""; fi
|
||||||
default_audio=$(echo "$infos" | jq -j '.[] | .DefaultAudio')
|
default_audio=$(echo "$infos" | jq -j '.[] | .DefaultAudio')
|
||||||
if [[ "$default_audio" == "null" ]]; then default_audio=""; fi
|
if [[ "$default_audio" == "null" ]]; then default_audio=""; fi
|
||||||
|
|
||||||
# Text
|
# Text
|
||||||
format_text=$(echo "$infos" | jq -j '.[] | .FormatText')
|
format_text=$(echo "$infos" | jq -j '.[] | .FormatText')
|
||||||
codec_text=$(echo "$infos" | jq -j '.[] | .CodecText')
|
codec_text=$(echo "$infos" | jq -j '.[] | .CodecText')
|
||||||
language_text=$(echo "$infos" | jq -j '.[] | .LanguageText')
|
language_text=$(echo "$infos" | jq -j '.[] | .LanguageText')
|
||||||
default_text=$(echo "$infos" | jq -j '.[] | .DefaultText')
|
default_text=$(echo "$infos" | jq -j '.[] | .DefaultText')
|
||||||
|
|
||||||
# Menu
|
# Menu
|
||||||
menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d')
|
menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d')
|
||||||
m=""
|
m=""
|
||||||
@@ -330,7 +331,7 @@ END_COMMENT
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $count -eq 0 ]; then
|
if [ "$count" -eq 0 ]; then
|
||||||
echo -e "\n${red}No file to transcode !${reset}"
|
echo -e "\n${red}No file to transcode !${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user