handbrake_for_plex.sh
shellcheck.sh
This commit is contained in:
@@ -59,71 +59,73 @@ fi
|
|||||||
|
|
||||||
logsize=$(wc -c <"$logfile")
|
logsize=$(wc -c <"$logfile")
|
||||||
|
|
||||||
if [ $logsize -ge 1000 ]; then
|
if [ "$logsize" -ge 1000 ]; then
|
||||||
cp "$logfile" "$logfile.old"
|
cp "$logfile" "$logfile.old"
|
||||||
truncate -s 0 "$logfile"
|
truncate -s 0 "$logfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#Move to trash after conversion
|
#Move to trash after conversion
|
||||||
trash=true
|
trash=true
|
||||||
|
|
||||||
|
command -v jq >/dev/null 2>&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; }
|
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
|
fzf_bin=0
|
||||||
if (! type fzf > /dev/null 2>&1); then
|
if (! type fzf >/dev/null 2>&1); then
|
||||||
echo -e "Install ${bold}fzf${reset} for a better experience !"
|
echo -e "Install ${bold}fzf${reset} for a better experience !"
|
||||||
echo -e "${italic}brew install fzf${reset}"
|
echo -e "${italic}brew install fzf${reset}"
|
||||||
fzf_bin=0
|
fzf_bin=0
|
||||||
else {
|
else
|
||||||
fzf_bin=1
|
{
|
||||||
fzf_args=(
|
fzf_bin=1
|
||||||
--height=8
|
fzf_args=(
|
||||||
--with-nth=2..
|
--height=8
|
||||||
--layout=reverse
|
--with-nth=2..
|
||||||
--info=hidden
|
--layout=reverse
|
||||||
--border
|
--info=hidden
|
||||||
)
|
--border
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
showHelp() {
|
showHelp() {
|
||||||
clear
|
clear
|
||||||
echo -e "\033[93mhandbrake_for_plex.sh\033[0m"
|
echo -e "\033[93mhandbrake_for_plex.sh\033[0m"
|
||||||
echo "Convert and rename video files for Plex:"
|
echo "Convert and rename video files for Plex:"
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
echo "USAGE: handbrake_for_plex.sh"
|
echo "USAGE: handbrake_for_plex.sh"
|
||||||
echo
|
echo
|
||||||
echo "Configure:"
|
echo "Configure:"
|
||||||
echo " -\$SRC : source folder (recursive)"
|
echo " -\$SRC : source folder (recursive)"
|
||||||
echo " -\$DEST : destination folder"
|
echo " -\$DEST : destination folder"
|
||||||
echo " -\$DEST_EXT : destination extension"
|
echo " -\$DEST_EXT : destination extension"
|
||||||
echo " -\$PRESET : preset HandBrake"
|
echo " -\$PRESET : preset HandBrake"
|
||||||
echo " and run script..."
|
echo " and run script..."
|
||||||
echo
|
echo
|
||||||
echo "OPTION:"
|
echo "OPTION:"
|
||||||
echo " -h display this help"
|
echo " -h display this help"
|
||||||
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 " -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
|
||||||
echo -e "To known Preset, run ${italic}HandBrakeCLI --preset-list${reset}"
|
echo -e "To known Preset, run ${italic}HandBrakeCLI --preset-list${reset}"
|
||||||
echo
|
echo
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
update_handbrake() {
|
update_handbrake() {
|
||||||
|
|
||||||
# https://www.thegeekdiary.com/how-to-install-dmg-file-on-mac-from-command-line/
|
# https://www.thegeekdiary.com/how-to-install-dmg-file-on-mac-from-command-line/
|
||||||
|
|
||||||
if [ "$(printf '%s\n' "$HB_VERSION" "$last_hbc_release" | sort -V | head -n1)" = "$HB_VERSION" ]; then
|
if [ "$(printf '%s\n' "$HB_VERSION" "$last_hbc_release" | sort -V | head -n1)" = "$HB_VERSION" ]; then
|
||||||
|
|
||||||
if [ "$HB_VERSION" != "$last_hbc_release" ]; then
|
if [ "$HB_VERSION" != "$last_hbc_release" ]; then
|
||||||
|
|
||||||
# release=$(gh release list -L 1 --repo HandBrake/HandBrake | cut -f1 | xargs -I{} gh release view {} --repo HandBrake/HandBrake)
|
# release=$(gh release list -L 1 --repo HandBrake/HandBrake | cut -f1 | xargs -I{} gh release view {} --repo HandBrake/HandBrake)
|
||||||
# news=$(echo "$release" | awk '/Upgrade Notice/,0')
|
# news=$(echo "$release" | awk '/Upgrade Notice/,0')
|
||||||
@@ -131,102 +133,101 @@ update_handbrake() {
|
|||||||
# asset=$(echo "$release" | awk '/Upgrade Notice/{exit} 1' | grep '^asset:' | grep -v '.sig' | grep 'HandBrakeCLI' | cut -f 2)
|
# asset=$(echo "$release" | awk '/Upgrade Notice/{exit} 1' | grep '^asset:' | grep -v '.sig' | grep 'HandBrakeCLI' | cut -f 2)
|
||||||
# url = https://github.com/HandBrake/HandBrake/releases/download/1.9.2/HandBrakeCLI-1.9.2.dmg
|
# url = https://github.com/HandBrake/HandBrake/releases/download/1.9.2/HandBrakeCLI-1.9.2.dmg
|
||||||
|
|
||||||
latest=$(curl --silent "https://api.github.com/repos/${gh_hbc_repo}/releases/latest")
|
latest=$(curl --silent "https://api.github.com/repos/${gh_hbc_repo}/releases/latest")
|
||||||
last_hbc_dl_url=$(echo "$latest" | grep 'HandBrakeCLI' | grep -v '.sig' | grep 'browser_download_url' | awk -F": " '{print $2}' | sed 's/"//g')
|
last_hbc_dl_url=$(echo "$latest" | grep 'HandBrakeCLI' | grep -v '.sig' | grep 'browser_download_url' | awk -F": " '{print $2}' | sed 's/"//g')
|
||||||
last_hbc_news=$(echo "$latest" | jq '.body')
|
last_hbc_news=$(echo "$latest" | jq '.body')
|
||||||
|
|
||||||
echo -e "${green}Current version: $HB_VERSION - Version $last_hbc_release available !${reset}"
|
echo -e "${green}Current version: $HB_VERSION - Version $last_hbc_release available !${reset}"
|
||||||
echo -e "$last_hbc_news"
|
echo -e "$last_hbc_news"
|
||||||
|
|
||||||
a=$(echo -e "${bold}Do you want to install HandBrakeCLI v$last_hbc_release (y/n)${reset}")
|
a=$(echo -e "${bold}Do you want to install HandBrakeCLI v$last_hbc_release (y/n)${reset}")
|
||||||
read -p "$a" hbc
|
read -p "$a" hbc
|
||||||
if [[ "$hbc" == "y" || "$hbc" == "Y" ]]; then
|
if [[ "$hbc" == "y" || "$hbc" == "Y" ]]; then
|
||||||
|
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
url=$(echo "$last_hbc_dl_url" | grep '.dmg')
|
url=$(echo "$last_hbc_dl_url" | grep '.dmg')
|
||||||
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
url=$(echo "$last_hbc_dl_url" | grep '.flatpak')
|
url=$(echo "$last_hbc_dl_url" | grep '.flatpak')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Downloading $url"
|
echo "Downloading $url"
|
||||||
dest=$HOME/Downloads
|
dest=$HOME/Downloads
|
||||||
filename=$(basename $url)
|
filename=$(basename "$url")
|
||||||
curl -L -O --output-dir $dest "$url"
|
curl -L -O --output-dir "$dest" "$url"
|
||||||
|
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
|
|
||||||
vol=$(hdiutil mount $dest/$filename | tail -1 | awk '{print $3}')
|
vol=$(hdiutil mount "$dest"/"$filename" | tail -1 | awk '{print $3}')
|
||||||
|
|
||||||
app=$vol/HandBrakeCLI
|
app=$vol/HandBrakeCLI
|
||||||
install_folder=$HOME/.local/bin/
|
install_folder=$HOME/.local/bin/
|
||||||
|
|
||||||
if [ -f "$app" ]; then
|
if [ -f "$app" ]; then
|
||||||
echo "Copying $filename to $install_folder"
|
echo "Copying $filename to $install_folder"
|
||||||
cp "$app" $install_folder
|
cp "$app" "$install_folder"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
x="$install_folder""HandBrakeCLI"
|
x="$install_folder""HandBrakeCLI"
|
||||||
if [ -f "$x" ]; then
|
if [ -f "$x" ]; then
|
||||||
v=$("$x" --version 2>/dev/null | awk '{print $2}')
|
v=$("$x" --version 2>/dev/null | awk '{print $2}')
|
||||||
if [ "$v" == "$last_hbc_release" ]; then
|
if [ "$v" == "$last_hbc_release" ]; then
|
||||||
echo -e "${green}HandBrakeCLI v$v successfully installed !${reset}"
|
echo -e "${green}HandBrakeCLI v$v successfully installed !${reset}"
|
||||||
else
|
else
|
||||||
echo -e "${red}HandBrakeCLI v$v installed !${reset}"
|
echo -e "${red}HandBrakeCLI v$v installed !${reset}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cd "$HOME" || exit
|
||||||
|
hdiutil unmount "$vol"
|
||||||
|
|
||||||
cd $HOME
|
|
||||||
hdiutil unmount $vol
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
installation() {
|
installation() {
|
||||||
#long_path=`pwd`"/"`basename "$0"`
|
#long_path=`pwd`"/"`basename "$0"`
|
||||||
long_path=$(realpath "$0")
|
long_path=$(realpath "$0")
|
||||||
|
|
||||||
echo -e "${bold}Installing "`basename "$0"`"${reset}"
|
echo -e "${bold}Installing $(basename "$0")${reset}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
fzf_install_paths=("/usr/local/bin" "$HOME/.local/bin" "$HOME")
|
fzf_install_paths=("/usr/local/bin" "$HOME/.local/bin" "$HOME")
|
||||||
|
|
||||||
if [ $fzf_bin -eq 1 ]; then
|
if [ $fzf_bin -eq 1 ]; then
|
||||||
prompt="Choose the install's path: "
|
prompt="Choose the install's path: "
|
||||||
|
|
||||||
choice=$(printf "Play %s\n" "${fzf_install_paths[@]}" | sort | fzf "${fzf_args[@]}" --prompt "$prompt")
|
choice=$(printf "Play %s\n" "${fzf_install_paths[@]}" | sort | fzf "${fzf_args[@]}" --prompt "$prompt")
|
||||||
install_path=${choice:5}
|
install_path=${choice:5}
|
||||||
|
|
||||||
else
|
else
|
||||||
read -e -p "Choose the install's path: " install_path
|
read -e -p "Choose the install's path: " install_path
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ ! $PATH =~ $install_path ]] && echo "$install_path in not in \$PATH !!"
|
[[ ! $PATH =~ $install_path ]] && echo "$install_path in not in \$PATH !!"
|
||||||
|
|
||||||
if [ -d "$install_path" ]; then
|
if [ -d "$install_path" ]; then
|
||||||
if [ -w "$install_path" ]; then
|
if [ -w "$install_path" ]; then
|
||||||
cp "$long_path" "$install_path"
|
cp "$long_path" "$install_path"
|
||||||
else
|
else
|
||||||
echo -e "${red}$install_path is not writeable !${reset}"
|
echo -e "${red}$install_path is not writeable !${reset}"
|
||||||
echo -e "${red}${bold}Using sudo ! Enter your password:${reset}"
|
echo -e "${red}${bold}Using sudo ! Enter your password:${reset}"
|
||||||
sudo cp "$long_path" "$install_path"
|
sudo cp "$long_path" "$install_path"
|
||||||
fi
|
fi
|
||||||
result=$?
|
result=$?
|
||||||
[ "$result" = 0 ] && echo -e "$long_path ${italic}is now installed in${reset} $install_path"
|
[ "$result" = 0 ] && echo -e "$long_path ${italic}is now installed in${reset} $install_path"
|
||||||
else
|
else
|
||||||
echo -e "${red}This folder does not exist !${reset}"
|
echo -e "${red}This folder does not exist !${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notification() {
|
notification() {
|
||||||
#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"
|
||||||
#image="$path_img/success.png"
|
#image="$path_img/success.png"
|
||||||
#image="$path_img/HandBrake.icns"
|
#image="$path_img/HandBrake.icns"
|
||||||
@@ -236,88 +237,92 @@ notification() {
|
|||||||
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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "h?i:o:p:z" opt; do
|
while getopts "h?i:o:p:z" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
h|\?)
|
h | \?)
|
||||||
showHelp
|
showHelp
|
||||||
exit 0
|
;;
|
||||||
;;
|
i)
|
||||||
i) input_path="$OPTARG"
|
input_path="$OPTARG"
|
||||||
;;
|
;;
|
||||||
o) output_path="$OPTARG"
|
o)
|
||||||
;;
|
output_path="$OPTARG"
|
||||||
p) profile="$OPTARG"
|
;;
|
||||||
;;
|
p)
|
||||||
z) installation
|
profile="$OPTARG"
|
||||||
exit 0
|
;;
|
||||||
;;
|
z)
|
||||||
esac
|
installation
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Reset OPTIND
|
# Reset OPTIND
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
|
# Update handbrake_for_plex.sh from GitHub
|
||||||
|
#Github="https://github.com/HandBrake/HandBrake"
|
||||||
Github="https://github.com/HandBrake/HandBrake"
|
|
||||||
# Public Repo:
|
# Public Repo:
|
||||||
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
#RawUrl="https://raw.githubusercontent.com/Bruno21/bashbirds/main/bashbirds.sh"
|
||||||
# Private Repo:
|
# Private Repo:
|
||||||
RawUrl="https://x-access-token:$GITHUB_TOKEN@raw.githubusercontent.com/HandBrake/HandBrake/main/bashbirds.sh"
|
#RawUrl="https://x-access-token:$GITHUB_TOKEN@raw.githubusercontent.com/HandBrake/HandBrake/main/bashbirds.sh"
|
||||||
|
|
||||||
### Check if there's a new release of the script:
|
### Check if there's a new release of the script:
|
||||||
LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
#LatestRelease="$(curl -s -r 0-50 $RawUrl | sed -n "/VERSION/s/VERSION=//p" | tr -d '"')"
|
||||||
#LatestChanges="$(curl -s -r 0-2000 $RawUrl | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
|
#LatestChanges="$(curl -s -r 0-2000 $RawUrl | sed -n "/ChangeNotes/s/# ChangeNotes: //p")"
|
||||||
LatestChanges="$(curl -s -r 0-2000 $RawUrl | grep "^### ChangeNotes:" | sed 's/### ChangeNotes://g')"
|
#LatestChanges="$(curl -s -r 0-2000 $RawUrl | grep "^### ChangeNotes:" | sed 's/### ChangeNotes://g')"
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
echo "_ _ ____ _ _ ___ ___ ____ ____ _ _ ____ ____ ____ ____ ___ _ ____ _ _ ";
|
echo "_ _ ____ _ _ ___ ___ ____ ____ _ _ ____ ____ ____ ____ ___ _ ____ _ _ "
|
||||||
echo "|__| |__| |\ | | \ |__] |__/ |__| |_/ |___ |___ | | |__/ |__] | |___ \/ ";
|
echo "|__| |__| |\ | | \ |__] |__/ |__| |_/ |___ |___ | | |__/ |__] | |___ \/ "
|
||||||
echo "| | | | | \| |__/ |__] | \ | | | \_ |___ | |__| | \ | |___ |___ _/\_ ";
|
echo "| | | | | \| |__/ |__] | \ | | | \_ |___ | |__| | \ | |___ |___ _/\_ "
|
||||||
echo " ";
|
echo " "
|
||||||
echo " ";
|
echo " "
|
||||||
echo " ";
|
echo " "
|
||||||
|
|
||||||
gh_hbc_repo="HandBrake/HandBrake"
|
gh_hbc_repo="HandBrake/HandBrake"
|
||||||
last_hbc_release=$(curl --silent "https://api.github.com/repos/${gh_hbc_repo}/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")")
|
last_hbc_release=$(curl --silent "https://api.github.com/repos/${gh_hbc_repo}/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")")
|
||||||
|
last_hbc_release="1.9.3"
|
||||||
version_brew=$(ls /opt/homebrew/Cellar/handbrake 2>/dev/null)
|
version_brew=$(ls /opt/homebrew/Cellar/handbrake 2>/dev/null)
|
||||||
cli=$(which HandBrakeCLI) # /Users/bruno/.local/bin/HandBrakeCLI
|
version_brew="1.9.1"
|
||||||
version_cli=$("$cli" --version 2>/dev/null | awk '{print $2}') # HandBrake 1.9.2
|
cli=$(which HandBrakeCLI) # /Users/bruno/.local/bin/HandBrakeCLI
|
||||||
|
version_cli=$("$cli" --version 2>/dev/null | awk '{print $2}') # HandBrake 1.9.2
|
||||||
|
|
||||||
|
#echo "$version_brew - $version_cli"
|
||||||
|
|
||||||
if [ "$version_brew" != "" ]; then
|
if [ "$version_brew" != "" ]; then
|
||||||
if [ "$version_cli" != "" ]; then
|
if [ "$version_cli" != "" ]; then
|
||||||
if [ "$(printf '%s\n' "$version_cli" "$version_brew" | sort -V | head -n1)" = "$version_cli" ]; then
|
if [ "$(printf '%s\n' "$version_cli" "$version_brew" | sort -V | head -n1)" = "$version_cli" ]; then
|
||||||
HANDBRAKE_CLI="/opt/homebrew/Cellar/handbrake/$version/bin/HandBrakeCLI"
|
HANDBRAKE_CLI="/opt/homebrew/Cellar/handbrake/$version_brew/bin/HandBrakeCLI"
|
||||||
HB_VERSION="$version_brew"
|
HB_VERSION="$version_brew"
|
||||||
else
|
else
|
||||||
HANDBRAKE_CLI="$cli"
|
HANDBRAKE_CLI="$cli"
|
||||||
HB_VERSION="$version_cli"
|
HB_VERSION="$version_cli"
|
||||||
|
|
||||||
update_handbrake
|
update_handbrake
|
||||||
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
HANDBRAKE_CLI="/opt/homebrew/Cellar/handbrake/$version/bin/HandBrakeCLI"
|
HANDBRAKE_CLI="/opt/homebrew/Cellar/handbrake/$version_brew/bin/HandBrakeCLI"
|
||||||
HB_VERSION="$version_brew"
|
HB_VERSION="$version_brew"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "$version_cli" != "" ]; then
|
if [ "$version_cli" != "" ]; then
|
||||||
HANDBRAKE_CLI="$cli"
|
HANDBRAKE_CLI="$cli"
|
||||||
HB_VERSION="$version_cli"
|
HB_VERSION="$version_cli"
|
||||||
|
|
||||||
update_handbrake
|
update_handbrake
|
||||||
else
|
else
|
||||||
echo -e "\n${red}HandBrake not installed!${reset}\n"
|
echo -e "\n${red}HandBrake not installed!${reset}\n"
|
||||||
@@ -343,34 +348,32 @@ count=0
|
|||||||
|
|
||||||
# Series: SxxEyy
|
# Series: SxxEyy
|
||||||
REGEX="([sS]([0-9]{2,}|[X]{2,})[eE]([0-9]{2,}|[Y]{2,}))"
|
REGEX="([sS]([0-9]{2,}|[X]{2,})[eE]([0-9]{2,}|[Y]{2,}))"
|
||||||
# Films:
|
# Films:
|
||||||
REGEX2=".[0-9]{4}" # année 2019 mais avec un caractère avant (chaine ne commence pas par 2019)
|
REGEX2=".[0-9]{4}" # année 2019 mais avec un caractère avant (chaine ne commence pas par 2019)
|
||||||
|
|
||||||
movies=()
|
movies=()
|
||||||
for FILE in "${SRC}"/**/*.{mkv,avi,mp4,m4v}
|
for FILE in "${SRC}"/**/*.{mkv,avi,mp4,m4v}; do
|
||||||
do
|
|
||||||
# Get file size
|
# Get file size
|
||||||
FILESIZE=$(stat -c%s "$FILE")
|
FILESIZE=$(stat -c%s "$FILE")
|
||||||
|
|
||||||
if (( FILESIZE > MAXSIZE )); then
|
if ((FILESIZE > MAXSIZE)); then
|
||||||
movies+=("${FILE}")
|
movies+=("${FILE}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
nb_movies=${#movies[@]}
|
nb_movies=${#movies[@]}
|
||||||
|
|
||||||
for FILE in "${movies[@]}"
|
for FILE in "${movies[@]}"; do
|
||||||
do
|
filename=$(basename "$FILE")
|
||||||
filename=$(basename "$FILE")
|
#extension=${filename##*.}
|
||||||
#extension=${filename##*.}
|
filename=${filename%.*}
|
||||||
filename=${filename%.*}
|
|
||||||
|
declare -a ft=()
|
||||||
declare -a ft=()
|
|
||||||
declare -a ct=()
|
declare -a ct=()
|
||||||
declare -a tt=()
|
declare -a tt=()
|
||||||
declare -a lt=()
|
declare -a lt=()
|
||||||
declare -a dt=()
|
declare -a dt=()
|
||||||
|
|
||||||
: <<'END_COMMENT'
|
: <<'END_COMMENT'
|
||||||
https://stackoverflow.com/questions/41231998/mediainfo-cli-command-line-interface-syntax-teaching-me-once-for-all
|
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")
|
media=$(mediainfo --Output=file:///$SCRIPT_DIR/template.txt "$FILE")
|
||||||
l=$(echo "$media" | sed -n '1p')
|
l=$(echo "$media" | sed -n '1p')
|
||||||
@@ -378,86 +381,84 @@ do
|
|||||||
echo -e "$info\n"
|
echo -e "$info\n"
|
||||||
END_COMMENT
|
END_COMMENT
|
||||||
|
|
||||||
# Suprrime [ Torrent911.io ]
|
# Suprrime [ Torrent911.io ]
|
||||||
a="[${filename#*[}"
|
a="[${filename#*[}"
|
||||||
a="${a%]*}] "
|
a="${a%]*}] "
|
||||||
filename=${filename#"$a"}
|
filename=${filename#"$a"}
|
||||||
|
|
||||||
# Séries
|
# Séries
|
||||||
if [[ $filename =~ $REGEX ]]; then
|
if [[ $filename =~ $REGEX ]]; then
|
||||||
MATCH="${BASH_REMATCH[1]}"
|
MATCH="${BASH_REMATCH[1]}"
|
||||||
# Remplace les . par des espaces
|
# Remplace les . par des espaces
|
||||||
e=$(echo "${filename%$MATCH*}" | sed 's/\./\ /g' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
|
e=$(echo "${filename%$MATCH*}" | sed 's/\./\ /g' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
|
||||||
# Capitalise chaque mot
|
# Capitalise chaque mot
|
||||||
f=( $e )
|
f=($e)
|
||||||
g=${f[@]^}
|
g=${f[@]^}
|
||||||
# Met en majuscule SxxExx
|
# Met en majuscule SxxExx
|
||||||
new_name="$g - ${MATCH^^}.$DEST_EXT"
|
new_name="$g - ${MATCH^^}.$DEST_EXT"
|
||||||
# Films
|
# Films
|
||||||
elif [[ $filename =~ $REGEX2 ]]; then
|
elif [[ $filename =~ $REGEX2 ]]; then
|
||||||
MATCH2="${BASH_REMATCH[0]}"
|
MATCH2="${BASH_REMATCH[0]}"
|
||||||
MATCH2=${MATCH2:1}
|
MATCH2=${MATCH2:1}
|
||||||
|
|
||||||
e=$(echo "${filename%$MATCH2*}" | sed 's/\./\ /g' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
|
e=$(echo "${filename%$MATCH2*}" | sed 's/\./\ /g' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
|
||||||
new_name="$e ($MATCH2).$DEST_EXT"
|
new_name="$e ($MATCH2).$DEST_EXT"
|
||||||
else
|
else
|
||||||
echo -e "${red}\nCould not find SXXEYY or YYYY pattern${reset}"
|
echo -e "${red}\nCould not find SXXEYY or YYYY pattern${reset}"
|
||||||
e=$(echo "${filename}" | sed 's/\./\ /g' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
|
e=$(echo "${filename}" | sed 's/\./\ /g' | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
|
||||||
read -e -p "Title: " -i "$e" e
|
read -e -p "Title: " -i "$e" e
|
||||||
new_name="$e.$DEST_EXT"
|
new_name="$e.$DEST_EXT"
|
||||||
#echo "new_name: $new_name"
|
#echo "new_name: $new_name"
|
||||||
#continue
|
#continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! command -v mediainfo &>/dev/null; then
|
||||||
if ! command -v mediainfo &> /dev/null; then
|
echo -e "${bold}mediainfo${reset} could not be found !\n"
|
||||||
echo -e "${bold}mediainfo${reset} could not be found !\n"
|
echo -e "You should install ${bold}mediainfo${reset}:\n"
|
||||||
echo -e "You should install ${bold}mediainfo${reset}:\n"
|
echo -e " - brew install mediainfo"
|
||||||
echo -e " - brew install mediainfo"
|
echo -e ""
|
||||||
echo -e ""
|
else
|
||||||
else
|
|
||||||
|
|
||||||
#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})')
|
||||||
|
|
||||||
infos=$(mediainfo "$FILE" --output=JSON | jq '.media.track')
|
|
||||||
|
|
||||||
while read row
|
|
||||||
do
|
|
||||||
type=$(echo "$row" | jq -r '.["@type"]')
|
|
||||||
|
|
||||||
if [[ "$type" == "General" ]]; then
|
infos=$(mediainfo "$FILE" --output=JSON | jq '.media.track')
|
||||||
general="$row"
|
|
||||||
#echo "$general" | jq
|
while read row; do
|
||||||
|
type=$(echo "$row" | jq -r '.["@type"]')
|
||||||
nb_audio=$(echo "$general" | jq -j '.AudioCount')
|
|
||||||
if [[ "$nb_audio" == "null" ]]; then nb_audio=0; fi
|
if [[ "$type" == "General" ]]; then
|
||||||
|
general="$row"
|
||||||
|
#echo "$general" | jq
|
||||||
|
|
||||||
|
nb_audio=$(echo "$general" | jq -j '.AudioCount')
|
||||||
|
if [[ "$nb_audio" == "null" ]]; then nb_audio=0; fi
|
||||||
nb_text=$(echo "$general" | jq -j '.TextCount')
|
nb_text=$(echo "$general" | jq -j '.TextCount')
|
||||||
if [[ "$nb_text" == "null" ]]; then nb_text=0; fi
|
if [[ "$nb_text" == "null" ]]; then nb_text=0; fi
|
||||||
nb_menu=$(echo "$general" | jq -j '.MenuCount')
|
nb_menu=$(echo "$general" | jq -j '.MenuCount')
|
||||||
if [[ "$nb_menu" == "null" ]]; then nb_menu=0; fi
|
if [[ "$nb_menu" == "null" ]]; then nb_menu=0; fi
|
||||||
|
|
||||||
format_fichier=$(echo "$general" | jq -j '.Format')
|
format_fichier=$(echo "$general" | jq -j '.Format')
|
||||||
filesize=$(echo "$general" | jq -j '.FileSize' | numfmt --to=si --format "%8.2f" | xargs)
|
filesize=$(echo "$general" | jq -j '.FileSize' | numfmt --to=si --format "%8.2f" | xargs)
|
||||||
duree=$(echo "$general" | jq -j '.Duration' | awk -F "." '{print $1}' | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}' | xargs)
|
duree=$(echo "$general" | jq -j '.Duration' | awk -F "." '{print $1}' | awk '{printf "%d:%02d:%02d", $1/3600, ($1/60)%60, $1%60}' | xargs)
|
||||||
|
|
||||||
elif [[ "$type" == "Video" ]]; then
|
elif [[ "$type" == "Video" ]]; then
|
||||||
video="$row"
|
video="$row"
|
||||||
#echo "$video" | jq
|
#echo "$video" | jq
|
||||||
|
|
||||||
fmt=$(echo "$video" | jq -j '.Format | select( . != null )')
|
fmt=$(echo "$video" | jq -j '.Format | select( . != null )')
|
||||||
|
|
||||||
if [ $fmt != "JPEG" ]; then
|
if [ "$fmt" != "JPEG" ]; then
|
||||||
format_video=$(echo "$video" | jq -j '.Format | select( . != null )')
|
format_video=$(echo "$video" | jq -j '.Format | select( . != null )')
|
||||||
format_profile=$(echo "$video" | jq -j '.Format_Profile | select( . != null )')
|
format_profile=$(echo "$video" | jq -j '.Format_Profile | select( . != null )')
|
||||||
format_level=$(echo "$video" | jq -j '.Format_Level | select( . != null )')
|
format_level=$(echo "$video" | jq -j '.Format_Level | select( . != null )')
|
||||||
codec_video=$(echo "$video" | jq -j '.CodecID | select( . != null )')
|
codec_video=$(echo "$video" | jq -j '.CodecID | select( . != null )')
|
||||||
width=$(echo "$video" | jq -j '.Width | select( . != null )')
|
width=$(echo "$video" | jq -j '.Width | select( . != null )')
|
||||||
height=$(echo "$video" | jq -j '.Height | select( . != null )')
|
height=$(echo "$video" | jq -j '.Height | select( . != null )')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [[ "$type" == "Audio" ]]; then
|
elif [[ "$type" == "Audio" ]]; then
|
||||||
audio="$row"
|
audio="$row"
|
||||||
#echo "$audio" | jq
|
#echo "$audio" | jq
|
||||||
|
|
||||||
format_audio=$(echo "$audio" | jq -j '.Format | select( . != null )')
|
format_audio=$(echo "$audio" | jq -j '.Format | select( . != null )')
|
||||||
format_addition=$(echo "$audio" | jq -j '.Format_AdditionalFeatures | select( . != null )')
|
format_addition=$(echo "$audio" | jq -j '.Format_AdditionalFeatures | select( . != null )')
|
||||||
@@ -467,10 +468,10 @@ END_COMMENT
|
|||||||
language_audio=$(echo "$audio" | jq -j '.Language | select( . != null )')
|
language_audio=$(echo "$audio" | jq -j '.Language | select( . != null )')
|
||||||
default_audio=$(echo "$audio" | jq -j '.Default | select( . != null )')
|
default_audio=$(echo "$audio" | jq -j '.Default | select( . != null )')
|
||||||
|
|
||||||
elif [[ "$type" == "Text" ]]; then
|
elif [[ "$type" == "Text" ]]; then
|
||||||
text="$row"
|
text="$row"
|
||||||
#echo "$text" | jq
|
#echo "$text" | jq
|
||||||
|
|
||||||
format_text=$(echo "$text" | jq -j '.Format | select( . != null )')
|
format_text=$(echo "$text" | jq -j '.Format | select( . != null )')
|
||||||
codec_text=$(echo "$text" | jq -j '.CodecID | select( . != null )')
|
codec_text=$(echo "$text" | jq -j '.CodecID | select( . != null )')
|
||||||
title_text=$(echo "$text" | jq -j '.Title | select( . != null )')
|
title_text=$(echo "$text" | jq -j '.Title | select( . != null )')
|
||||||
@@ -482,33 +483,31 @@ END_COMMENT
|
|||||||
tt+=("$title_text")
|
tt+=("$title_text")
|
||||||
lt+=("$language_text")
|
lt+=("$language_text")
|
||||||
dt+=("$default_text")
|
dt+=("$default_text")
|
||||||
|
|
||||||
elif [[ "$type" == "Menu" ]]; then
|
elif [[ "$type" == "Menu" ]]; then
|
||||||
menu="$row"
|
menu="$row"
|
||||||
#echo "$menu" | jq
|
#echo "$menu" | jq
|
||||||
fi
|
fi
|
||||||
done < <(echo "$infos" | jq -c '.[]')
|
done < <(echo "$infos" | jq -c '.[]')
|
||||||
|
|
||||||
|
|
||||||
# Menu
|
# Menu
|
||||||
|
|
||||||
#menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d')
|
#menu=$(echo "$infos" | jq -j '.[] | .Menu' | sed '1d;$d')
|
||||||
menus=$(echo "$menu" | jq -j '.extra' | sed '1d;$d')
|
menus=$(echo "$menu" | jq -j '.extra' | sed '1d;$d')
|
||||||
#echo "menus: $menus"
|
#echo "menus: $menus"
|
||||||
|
|
||||||
m=()
|
m=()
|
||||||
n=1
|
n=1
|
||||||
while IFS= read -r line
|
while IFS= read -r line; do
|
||||||
do
|
# L'apparition
|
||||||
# L'apparition
|
# "_00_07_57_920": "en:00:07:57.920",
|
||||||
# "_00_07_57_920": "en:00:07:57.920",
|
|
||||||
|
# Kandahar
|
||||||
# Kandahar
|
# "_00_00_00_000": "1. Studio Logo",
|
||||||
# "_00_00_00_000": "1. Studio Logo",
|
|
||||||
|
|
||||||
REGEX1="^_(0[0-9]|1[0-9]|2[0-3])_([0-5][0-9])_([0-5][0-9])_([0-9][0-9][0-9])$"
|
REGEX1="^_(0[0-9]|1[0-9]|2[0-3])_([0-5][0-9])_([0-5][0-9])_([0-9][0-9][0-9])$"
|
||||||
|
|
||||||
if [[ ${line:3:13} =~ $REGEX1 ]]; then
|
if [[ ${line:3:13} =~ $REGEX1 ]]; then
|
||||||
|
|
||||||
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}')
|
||||||
@@ -518,7 +517,6 @@ END_COMMENT
|
|||||||
# t: "_00_07_57_920"
|
# t: "_00_07_57_920"
|
||||||
# c: "en:00:07:57.920",
|
# c: "en:00:07:57.920",
|
||||||
|
|
||||||
|
|
||||||
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/^/ /' | xargs)
|
cc=$(echo "$c" | tr -d '"' | xargs | sed 's/,$//' | sed 's/^/ /' | xargs)
|
||||||
@@ -527,16 +525,16 @@ END_COMMENT
|
|||||||
# L'apparition
|
# L'apparition
|
||||||
# tt: 00h07mm57
|
# tt: 00h07mm57
|
||||||
# cc: en:00:07:57.920
|
# cc: en:00:07:57.920
|
||||||
|
|
||||||
#m+=("$n:$tt")
|
#m+=("$n:$tt")
|
||||||
m+=("$n:$cc ($tt)")
|
m+=("$n:$cc ($tt)")
|
||||||
((n=n+1))
|
((n = n + 1))
|
||||||
fi
|
fi
|
||||||
done <<< "$menus"
|
done <<<"$menus"
|
||||||
|
|
||||||
((count++))
|
((count++))
|
||||||
echo -e "\n\n${bold}(${red}$count${reset}${bold} / $nb_movies) $filename${reset}"
|
echo -e "\n\n${bold}(${red}$count${reset}${bold} / $nb_movies) $filename${reset}"
|
||||||
|
|
||||||
echo -e "\n${bold}General:${reset}"
|
echo -e "\n${bold}General:${reset}"
|
||||||
printf " %-20s %-35s \n" "Format de fichier:" "${format_fichier}"
|
printf " %-20s %-35s \n" "Format de fichier:" "${format_fichier}"
|
||||||
printf " %-20s %-35s \n" "Taille de fichier:" "${filesize}"
|
printf " %-20s %-35s \n" "Taille de fichier:" "${filesize}"
|
||||||
@@ -548,7 +546,7 @@ END_COMMENT
|
|||||||
printf " %-20s %-35s \n" "Level:" "${format_level}"
|
printf " %-20s %-35s \n" "Level:" "${format_level}"
|
||||||
printf " %-20s %-35s \n" "Codec:" "${codec_video}"
|
printf " %-20s %-35s \n" "Codec:" "${codec_video}"
|
||||||
printf " %-20s %-35s \n" "Dimensions:" "${width} x ${height}"
|
printf " %-20s %-35s \n" "Dimensions:" "${width} x ${height}"
|
||||||
|
|
||||||
echo -e "\n${bold}Audio:${reset}"
|
echo -e "\n${bold}Audio:${reset}"
|
||||||
printf " %-20s %-35s \n" "Format audio:" "${format_audio}"
|
printf " %-20s %-35s \n" "Format audio:" "${format_audio}"
|
||||||
printf " %-20s %-35s \n" "Format additionnel:" "${format_addition}"
|
printf " %-20s %-35s \n" "Format additionnel:" "${format_addition}"
|
||||||
@@ -557,7 +555,7 @@ END_COMMENT
|
|||||||
printf " %-20s %-35s \n" "Titre:" "${title_audio}"
|
printf " %-20s %-35s \n" "Titre:" "${title_audio}"
|
||||||
printf " %-20s %-35s \n" "Language:" "${language_audio}"
|
printf " %-20s %-35s \n" "Language:" "${language_audio}"
|
||||||
printf " %-20s %-35s \n" "Defaut:" "${default_audio}"
|
printf " %-20s %-35s \n" "Defaut:" "${default_audio}"
|
||||||
|
|
||||||
#if [ "$nb_text" -ge 1 ]; then
|
#if [ "$nb_text" -ge 1 ]; then
|
||||||
# echo -e "\n${bold}Text:${reset}"
|
# echo -e "\n${bold}Text:${reset}"
|
||||||
# printf " %-20s %-35s \n" "Titre:" "${title_text}"
|
# printf " %-20s %-35s \n" "Titre:" "${title_text}"
|
||||||
@@ -568,12 +566,11 @@ END_COMMENT
|
|||||||
#fi
|
#fi
|
||||||
|
|
||||||
if [ "$nb_text" -ge 1 ]; then
|
if [ "$nb_text" -ge 1 ]; then
|
||||||
|
|
||||||
for val in ${!ft[@]}
|
for val in "${!ft[@]}"; do
|
||||||
do
|
|
||||||
index=${val}
|
index=${val}
|
||||||
((index++))
|
((index++))
|
||||||
|
|
||||||
echo -e "\n${bold}Text $index:${reset}"
|
echo -e "\n${bold}Text $index:${reset}"
|
||||||
printf " %-20s %-35s \n" "Titre:" "${tt[$val]}"
|
printf " %-20s %-35s \n" "Titre:" "${tt[$val]}"
|
||||||
printf " %-20s %-35s \n" "Format:" "${ft[$val]}"
|
printf " %-20s %-35s \n" "Format:" "${ft[$val]}"
|
||||||
@@ -583,100 +580,94 @@ END_COMMENT
|
|||||||
done
|
done
|
||||||
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}"
|
||||||
for elem in "${m[@]}";
|
for elem in "${m[@]}"; do
|
||||||
do
|
|
||||||
#echo "${elem}"
|
#echo "${elem}"
|
||||||
# en:00:07:57.920 : 00h07mm57
|
# en:00:07:57.920 : 00h07mm57
|
||||||
|
|
||||||
c=$(echo "${elem}" | awk -F":" '{print $1}')
|
c=$(echo "${elem}" | awk -F":" '{print $1}')
|
||||||
t=$(echo "${elem}" | awk -F":" '{print $2}')
|
t=$(echo "${elem}" | awk -F":" '{print $2}')
|
||||||
printf " %-20s %-35s \n" "$c:" "${t}"
|
printf " %-20s %-35s \n" "$c:" "${t}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi # if mediainfo installed
|
fi # if mediainfo installed
|
||||||
|
|
||||||
|
file_export="$DEST"/"$new_name"
|
||||||
|
|
||||||
|
if [ ! -f "$file_export" ]; then
|
||||||
|
#echo -e "\n${yellow}Convert $FILE${reset} ${bold}->${reset} ${green}$file_export${reset}"
|
||||||
|
z="\n${yellow}Convert $FILE${reset} ${bold}->${reset} ${green}$file_export${reset}"
|
||||||
|
|
||||||
|
#echo -e "${red}language_text: ${language_text}${reset}" # fr-FR (killers of...) fr-FR (yannick)
|
||||||
|
#echo -e "${red}lt: ${lt[@]}${reset}" # fr fr-FR (killers of...) fr-FR (yannick)
|
||||||
|
#echo -e "${red}SUBTITLE_LIST: $SUBTITLE_LIST${reset}" # eng,fre
|
||||||
|
|
||||||
|
if [ "$nb_text" -ge 1 ]; then
|
||||||
|
echo -e "$z (with ${bold}${language_text}${reset} subtitle track)" # with fr-FR
|
||||||
|
$HANDBRAKE_CLI -i "$FILE" -o "$file_export" "$PRESET" --subtitle-lang-list "$SUBTITLE_LIST" --all-subtitles 2>>$logfile
|
||||||
|
else
|
||||||
|
echo -e "$z"
|
||||||
|
$HANDBRAKE_CLI -i "$FILE" -o "$file_export" "$PRESET" 2>>$logfile
|
||||||
|
fi
|
||||||
|
result=$?
|
||||||
|
|
||||||
|
echo
|
||||||
|
|
||||||
file_export="$DEST"/"$new_name"
|
if [ "$result" = 0 ]; then
|
||||||
|
echo -e "${green}$new_name available in $DEST${reset}"
|
||||||
if [ ! -f "$file_export" ]; then
|
notification "HandBrake for Plex" "$new_name available in $DEST" $result
|
||||||
#echo -e "\n${yellow}Convert $FILE${reset} ${bold}->${reset} ${green}$file_export${reset}"
|
fi
|
||||||
z="\n${yellow}Convert $FILE${reset} ${bold}->${reset} ${green}$file_export${reset}"
|
|
||||||
|
# Open DEST file in an app
|
||||||
#echo -e "${red}language_text: ${language_text}${reset}" # fr-FR (killers of...) fr-FR (yannick)
|
if [ "$APP" != "" ]; then
|
||||||
#echo -e "${red}lt: ${lt[@]}${reset}" # fr fr-FR (killers of...) fr-FR (yannick)
|
if [[ $(command -v mdfind) == "" ]]; then
|
||||||
#echo -e "${red}SUBTITLE_LIST: $SUBTITLE_LIST${reset}" # eng,fre
|
echo -e "\n${red}mdfind not find ! mdfind is a part macOS.${reset}"
|
||||||
|
|
||||||
if [ "$nb_text" -ge 1 ]; then
|
|
||||||
echo -e "$z (with ${bold}${language_text}${reset} subtitle track)" # with fr-FR
|
|
||||||
$HANDBRAKE_CLI -i "$FILE" -o "$file_export" "$PRESET" --subtitle-lang-list "$SUBTITLE_LIST" --all-subtitles 2>> $logfile
|
|
||||||
else
|
else
|
||||||
echo -e "$z"
|
#x=$(mdfind -name "$APP" kind:application)
|
||||||
$HANDBRAKE_CLI -i "$FILE" -o "$file_export" "$PRESET" 2>> $logfile
|
# /usr/bin/mdfind $@ 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2)
|
||||||
fi
|
x=$(mdfind -name "$APP" kind:application 2>/dev/null)
|
||||||
echo
|
|
||||||
|
if [ "$x" != "" ]; then
|
||||||
result=$?
|
if [ -f "$file_export" ]; then
|
||||||
if [ "$result" = 0 ]; then
|
echo -e "\n${bold}Opening $file_export in $APP...${reset}"
|
||||||
echo -e "${green}$new_name available in $DEST${reset}"
|
open -a "$APP" "$file_export"
|
||||||
notification "HandBrake for Plex" "$new_name available in $DEST" $result
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Open DEST file in an app
|
|
||||||
if [ "$APP" != "" ]; then
|
|
||||||
if [[ $(command -v mdfind) == "" ]]; then
|
|
||||||
echo -e "\n${red}mdfind not find ! mdfind is a part macOS.${reset}"
|
|
||||||
else
|
|
||||||
#x=$(mdfind -name "$APP" kind:application)
|
|
||||||
# /usr/bin/mdfind $@ 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2)
|
|
||||||
x=$(mdfind -name "$APP" kind:application 2> /dev/null)
|
|
||||||
|
|
||||||
if [ "$x" != "" ]; then
|
|
||||||
if [ -f "$file_export" ]; then
|
|
||||||
echo -e "\n${bold}Opening $file_export in $APP...${reset}"
|
|
||||||
open -a "$APP" "$file_export"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e "\n${red}$APP was not found...${reset}"
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -e "\n${red}$APP was not found...${reset}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Move SRC file to trash
|
# Move SRC file to trash
|
||||||
parent_folder=${FILE%/*}
|
parent_folder=${FILE%/*}
|
||||||
if [ "$trash" = true ] && [[ "$OSTYPE" == "darwin"* ]]; then
|
if [ "$trash" = true ] && [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
||||||
osascript -e "tell application \"Finder\" to delete POSIX file \"${FILE}\"" >/dev/null
|
osascript -e "tell application \"Finder\" to delete POSIX file \"${FILE}\"" >/dev/null
|
||||||
fi
|
fi
|
||||||
if [ "$trash" = true ] && [[ "$OSTYPE" == "linux-gnu"* ]] && [[ $(command -v gio) != "" ]]; then
|
if [ "$trash" = true ] && [[ "$OSTYPE" == "linux-gnu"* ]] && [[ $(command -v gio) != "" ]]; then
|
||||||
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
||||||
gio trash "$FILE" >/dev/null
|
gio trash "$FILE" >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "$(echo "${parent_folder}/"*)" = "${parent_folder}/*" ] && rm -rf "${parent_folder}";
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
else
|
[ "$(echo "${parent_folder}/"*)" = "${parent_folder}/*" ] && rm -rf "${parent_folder}"
|
||||||
echo -e "\n${green}$file_export already transcoded !${reset}\n"
|
|
||||||
((already_transcoded+=1))
|
echo ""
|
||||||
fi
|
|
||||||
|
else
|
||||||
|
echo -e "\n${green}$file_export already transcoded !${reset}\n"
|
||||||
FILESIZE=
|
((already_transcoded += 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILESIZE=
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
transcoded=$((count-already_transcoded))
|
transcoded=$((count - already_transcoded))
|
||||||
|
|
||||||
if [ "$transcoded" -eq 0 ]; then
|
if [ "$transcoded" -eq 0 ]; then
|
||||||
echo -e "\n${red}No file to transcode !${reset}"
|
echo -e "\n${red}No file to transcode !${reset}"
|
||||||
else
|
else
|
||||||
echo -e "\n${green}${transcoded} files successfully transcoded !${reset}"
|
echo -e "\n${green}${transcoded} files successfully transcoded !${reset}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user