From bb2b797bacd841e2d3ded7870ad5dcb697cb9ec3 Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Thu, 4 Aug 2022 10:47:47 +0200 Subject: [PATCH] handbrake_for_plex.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -ajout d’une notification quand la conversion est finie -ajout d’un fichier /tmp/HandBrake.log pour limiter le verbiage --- handbrake_for_plex.sh | 65 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/handbrake_for_plex.sh b/handbrake_for_plex.sh index 8e7443e..7264812 100755 --- a/handbrake_for_plex.sh +++ b/handbrake_for_plex.sh @@ -25,7 +25,7 @@ showHelp() { echo "USAGE: handbrake_for_plex.sh" echo echo "Configure:" - echo " -\$SRC : source folder (récursive)" + echo " -\$SRC : source folder (recursive)" echo " -\$DEST : destination folder" echo " -\$DEST_EXT : destination extension" echo " -\$PRESET : preset HandBrake" @@ -33,7 +33,7 @@ showHelp() { echo echo "OPTION:" echo " -h display this help" - echo " -i source folder (récursive)" + echo " -i source folder (recursive)" echo " -o destination folder" echo " -p preset HandBrake" echo @@ -44,6 +44,32 @@ showHelp() { exit 0 } +notification() { + #path_img=`dirname "$0"` + path_img=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + + if [ $3 -eq 0 ]; + then + sound="Glass" + #message="Envoi terminé sur $2 !" + image="$path_img/success.png" + #image="$path_img/HandBrake.icns" + else + sound="Basso" + #message="Echec lors de l'envoi sur $2" + image="$path_img/error.png" + fi + + if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v zenity)" ]; then + zenity --title="$1" --notification --text="$2" + elif [[ "$OSTYPE" == "darwin"* ]] && [ -x "$(command -v terminal-notifier)" ]; then + # -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" -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 + fi +} + while getopts "h?i:o:p:" opt; do case "$opt" in h|\?) @@ -85,10 +111,14 @@ DEST_EXT=mp4 # Only files larger than $MAXSIZE will be processed MAXSIZE=30000000 +#MAXSIZE=300 # Open converted video file in an application APP="Subler" +# log +logfile=/tmp/HandBrake.log + ### echo "_ _ ____ _ _ ___ ___ ____ ____ _ _ ____ ____ ____ ____ ___ _ ____ _ _ "; @@ -101,15 +131,17 @@ echo " version=$(ls /opt/homebrew/Cellar/handbrake 2>/dev/null) if [ "$version" != "" ]; then HANDBRAKE_CLI="/opt/homebrew/Cellar/handbrake/$version/bin/HandBrakeCLI" - echo -e "${bold}Handbrake $version${reset}\n" + echo -e "${bold}HandBrake $version${reset}" + echo -e "$HANDBRAKE_CLI\n" else { cli=$(which HandBrakeCLI) if [ "$cli" != "" ]; then HANDBRAKE_CLI="$cli" version=$("$HANDBRAKE_CLI" --version 2>/dev/null | sed -n '1p') - echo "${bold}$version${reset}" + echo -e "${bold}HandBrake $version${reset}" + echo -e "$HANDBRAKE_CLI\n" else - echo -e "${red}handbrake not installed!${reset}\n" + echo -e "${red}HandBrake not installed!${reset}\n" exit 1 fi } @@ -142,7 +174,7 @@ do FILESIZE=$(stat -c%s "$FILE") if (( FILESIZE > MAXSIZE )); then - + : <<'END_COMMENT' https://stackoverflow.com/questions/41231998/mediainfo-cli-command-line-interface-syntax-teaching-me-once-for-all media=$(mediainfo --Output=file:///$SCRIPT_DIR/template.txt "$FILE") @@ -223,15 +255,15 @@ END_COMMENT done <<< "$menu" - echo -e "\n\n🎬 ${bold}$filename${reset}" + echo -e "\n\n ${bold}$filename${reset}" - echo -e "\n${bold}Général:${reset}" + echo -e "\n${bold}General:${reset}" printf " %-20s %-35s \n" "Format de fichier:" "${format_fichier}" printf " %-20s %-35s \n" "Taille de fichier:" "${filesize}" - printf " %-21s %-35s \n" "Durée:" "${duree}" + printf " %-21s %-35s \n" "Duree:" "${duree}" - echo -e "\n${bold}Vidéo:${reset}" - printf " %-21s %-35s \n" "Format vidéo:" "${format_video}" + echo -e "\n${bold}Video:${reset}" + printf " %-21s %-35s \n" "Format video:" "${format_video}" printf " %-20s %-35s \n" "Profile:" "${format_profile}" printf " %-20s %-35s \n" "Level:" "${format_level}" printf " %-20s %-35s \n" "Codec:" "${codec_video}" @@ -265,7 +297,14 @@ END_COMMENT if [ ! -f "$file_export" ]; then echo -e "\n${yellow}Convert $FILE${reset} ${bold}->${reset} ${green}$file_export${reset}\n" - $HANDBRAKE_CLI -i "$FILE" -o "$file_export" "$PRESET" + $HANDBRAKE_CLI -i "$FILE" -o "$file_export" "$PRESET" 2> $logfile + + result=$? + if [ "$result" = 0 ]; then + notification "HandBrake for Plex" "$new_name available in $DEST" $result + fi + + echo "" ((count++)) @@ -287,7 +326,7 @@ END_COMMENT fi - + FILESIZE= fi done