handbrake_for_plex.sh

bugfix with chapters
This commit is contained in:
2023-07-21 09:57:28 +02:00
parent ef91f1a68e
commit 17a975effa

View File

@@ -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; } 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() { showHelp() {
clear clear
@@ -36,6 +52,7 @@ showHelp() {
echo " -i source folder (recursive)" echo " -i source folder (recursive)"
echo " -o destination folder" echo " -o destination folder"
echo " -p preset HandBrake" echo " -p preset HandBrake"
echo " -z install handbrake_for_plex.sh"
echo echo
echo -e "Example: ${italic}./handbrake_for_plex.sh -i $HOME/Downloads -o $HOME/Images -p 'Apple 720p30 Surround'${reset}" echo -e "Example: ${italic}./handbrake_for_plex.sh -i $HOME/Downloads -o $HOME/Images -p 'Apple 720p30 Surround'${reset}"
echo echo
@@ -44,6 +61,42 @@ showHelp() {
exit 0 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() { notification() {
#path_img=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) #path_img=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
@@ -67,7 +120,7 @@ notification() {
fi fi
} }
while getopts "h?i:o:p:" opt; do while getopts "h?i:o:p:z" opt; do
case "$opt" in case "$opt" in
h|\?) h|\?)
showHelp showHelp
@@ -79,6 +132,9 @@ while getopts "h?i:o:p:" opt; do
;; ;;
p) profile="$OPTARG" p) profile="$OPTARG"
;; ;;
z) installation
exit 0
;;
esac esac
done done
@@ -266,16 +322,17 @@ END_COMMENT
# Menu # Menu
menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d') menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d')
m="" m=()
while IFS= read -r line while IFS= read -r line
do do
t=$(echo "$line" | awk -F": " '{print $1}') t=$(echo "$line" | awk -F": " '{print $1}')
c=$(echo "$line" | awk -F": " '{print $2}') 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.*//') 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" done <<< "$menu"
echo -e "\n\n${bold}(${red}$(( count + 1 ))${reset}${bold} / $nb_movies) - $filename${reset}" echo -e "\n\n${bold}(${red}$(( count + 1 ))${reset}${bold} / $nb_movies) - $filename${reset}"
@@ -309,8 +366,13 @@ END_COMMENT
fi fi
if [ "$nb_menu" -ge 1 ]; then if [ "$nb_menu" -ge 1 ]; then
echo -e "\n${bold}Menu:${reset}" echo -e "\n${bold}Menu:${reset}"
echo -e "$m" 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
fi # if mediainfo installed fi # if mediainfo installed