From 17a975effab39a77ef6e0926ed66123081d94280 Mon Sep 17 00:00:00 2001 From: Bruno21 Date: Fri, 21 Jul 2023 09:57:28 +0200 Subject: [PATCH] handbrake_for_plex.sh bugfix with chapters --- handbrake_for_plex.sh | 74 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/handbrake_for_plex.sh b/handbrake_for_plex.sh index e0d458e..06017d8 100755 --- a/handbrake_for_plex.sh +++ b/handbrake_for_plex.sh @@ -15,6 +15,22 @@ shopt -s globstar command -v jq >/dev/null 2>&1 || { echo -e "${bold}93mhandbrake_for_plex${reset} require ${bold}jq${reset} but it's not installed.\nRun ${italic}(brew install jq)${reset}\nAborting..." >&2; exit 1; } +fzf_bin=0 +if (! type fzf > /dev/null 2>&1); then + echo -e "Install ${bold}fzf${reset} for a better experience !" + echo -e "${italic}brew install fzf${reset}" + fzf_bin=0 +else { + fzf_bin=1 + fzf_args=( + --height=8 + --with-nth=2.. + --layout=reverse + --info=hidden + --border + ) + } +fi showHelp() { clear @@ -36,6 +52,7 @@ showHelp() { echo " -i source folder (recursive)" echo " -o destination folder" echo " -p preset HandBrake" + echo " -z install handbrake_for_plex.sh" echo echo -e "Example: ${italic}./handbrake_for_plex.sh -i $HOME/Downloads -o $HOME/Images -p 'Apple 720p30 Surround'${reset}" echo @@ -44,6 +61,42 @@ showHelp() { exit 0 } +installation() { + #long_path=`pwd`"/"`basename "$0"` + long_path=$(realpath "$0") + + echo -e "${bold}Installing "`basename "$0"`"${reset}" + echo + + fzf_install_paths=("/usr/local/bin" "$HOME/.local/bin" "$HOME") + + if [ $fzf_bin -eq 1 ]; then + prompt="Choose the install's path: " + + choice=$(printf "Play %s\n" "${fzf_install_paths[@]}" | sort | fzf "${fzf_args[@]}" --prompt "$prompt") + install_path=${choice:5} + + else + read -e -p "Choose the install's path: " install_path + fi + + [[ ! $PATH =~ $install_path ]] && echo "$install_path in not in \$PATH !!" + + if [ -d "$install_path" ]; then + if [ -w "$install_path" ]; then + cp "$long_path" "$install_path" + else + echo -e "${red}$install_path is not writeable !${reset}" + echo -e "${red}${bold}Using sudo ! Enter your password:${reset}" + sudo cp "$long_path" "$install_path" + fi + result=$? + [ "$result" = 0 ] && echo -e "$long_path ${italic}is now installed in${reset} $install_path" + else + echo -e "${red}This folder does not exist !${reset}" + fi +} + notification() { #path_img=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) @@ -67,7 +120,7 @@ notification() { fi } -while getopts "h?i:o:p:" opt; do +while getopts "h?i:o:p:z" opt; do case "$opt" in h|\?) showHelp @@ -79,6 +132,9 @@ while getopts "h?i:o:p:" opt; do ;; p) profile="$OPTARG" ;; + z) installation + exit 0 + ;; esac done @@ -266,16 +322,17 @@ END_COMMENT # Menu menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d') - m="" + m=() while IFS= read -r line do t=$(echo "$line" | awk -F": " '{print $1}') c=$(echo "$line" | awk -F": " '{print $2}') tt=$(echo "$t" | sed -n '1 s/"//gp' | xargs | sed 's/^_//' | sed 's/_/h/1' | sed 's/_/mm/1' | sed 's/_/s/1' | sed 's/s.*//') - cc=$(echo "$c" | tr -d '"' | xargs | awk -F ":" '{print $2}' | sed 's/,$//' | sed 's/^/ /') + #cc=$(echo "$c" | tr -d '"' | xargs | awk -F ":" '{print $2}' | sed 's/,$//' | sed 's/^/ /') + cc=$(echo "$c" | tr -d '"' | xargs | sed 's/,$//' | sed 's/^/ /') - m+="$cc : $tt\n" + m+=("$cc : $tt") done <<< "$menu" echo -e "\n\n${bold}(${red}$(( count + 1 ))${reset}${bold} / $nb_movies) - $filename${reset}" @@ -309,8 +366,13 @@ END_COMMENT fi if [ "$nb_menu" -ge 1 ]; then - echo -e "\n${bold}Menu:${reset}" - echo -e "$m" + echo -e "\n${bold}Menu:${reset}" + for elem in "${m[@]}"; + do + c=$(echo "${elem}" | awk -F":" '{print $1}') + t=$(echo "${elem}" | awk -F":" '{print $2}') + printf " %-20s %-35s \n" "$c:" "${t}" + done fi fi # if mediainfo installed