handbrake_for_plex.sh
- move to trash after conversion (gio trash on linux) - compteur de vidéos
This commit is contained in:
@@ -114,8 +114,13 @@ MAXSIZE=30000000
|
||||
APP="Subler"
|
||||
|
||||
# log
|
||||
# this reduce handbrake verbosity
|
||||
logfile=/tmp/HandBrake.log
|
||||
|
||||
#Move to trash after conversion
|
||||
trash=true
|
||||
|
||||
|
||||
###
|
||||
|
||||
echo "_ _ ____ _ _ ___ ___ ____ ____ _ _ ____ ____ ____ ____ ___ _ ____ _ _ ";
|
||||
@@ -161,16 +166,24 @@ REGEX="([sS]([0-9]{2,}|[X]{2,})[eE]([0-9]{2,}|[Y]{2,}))"
|
||||
# Films: 2
|
||||
REGEX2="[0-9]{4}"
|
||||
|
||||
movies=()
|
||||
for FILE in "${SRC}"/**/*.{mkv,avi,mp4,m4v}
|
||||
do
|
||||
# Get file size
|
||||
FILESIZE=$(stat -c%s "$FILE")
|
||||
|
||||
if (( FILESIZE > MAXSIZE )); then
|
||||
movies+=("${FILE}")
|
||||
fi
|
||||
done
|
||||
nb_movies=${#movies[@]}
|
||||
|
||||
for FILE in "${movies[@]}"
|
||||
do
|
||||
filename=$(basename "$FILE")
|
||||
#extension=${filename##*.}
|
||||
filename=${filename%.*}
|
||||
|
||||
# Get file size
|
||||
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
|
||||
@@ -182,11 +195,11 @@ END_COMMENT
|
||||
|
||||
if [[ $filename =~ $REGEX ]]; then
|
||||
MATCH="${BASH_REMATCH[1]}"
|
||||
e=$(echo ${filename%$MATCH*} | sed 's/\./\ /g' | xargs)
|
||||
e=$(echo "${filename%$MATCH*}" | sed 's/\./\ /g' | xargs)
|
||||
new_name="$e - $MATCH.$DEST_EXT"
|
||||
elif [[ $filename =~ $REGEX2 ]]; then
|
||||
MATCH2="${BASH_REMATCH[0]}"
|
||||
e=$(echo ${filename%$MATCH2*} | sed 's/\./\ /g' | xargs)
|
||||
e=$(echo "${filename%$MATCH2*}" | sed 's/\./\ /g' | xargs)
|
||||
new_name="$e ($MATCH2).$DEST_EXT"
|
||||
else
|
||||
echo "Could not find SXXEYY pattern"
|
||||
@@ -255,8 +268,7 @@ END_COMMENT
|
||||
m+="$cc : $tt\n"
|
||||
done <<< "$menu"
|
||||
|
||||
|
||||
echo -e "\n\n ${bold}$filename${reset}"
|
||||
echo -e "\n\n${bold}(${red}$(( count + 1 ))${reset}${bold} / $nb_movies) - $filename${reset}"
|
||||
|
||||
echo -e "\n${bold}General:${reset}"
|
||||
printf " %-20s %-35s \n" "Format de fichier:" "${format_fichier}"
|
||||
@@ -306,33 +318,57 @@ END_COMMENT
|
||||
fi
|
||||
|
||||
|
||||
echo ""
|
||||
((count++))
|
||||
|
||||
# Open DEST file in an app
|
||||
if [ "$APP" != "" ]; then
|
||||
if [[ $(command -v mdfind) == "" ]]; then
|
||||
echo "mdfind not find ! mdfind is a part macOS."
|
||||
echo -e "\n${red}mdfind not find ! mdfind is a part macOS.${reset}"
|
||||
else
|
||||
x=$(mdfind -name "$APP" kind:application)
|
||||
if [ "$x" != "" ]; then
|
||||
echo -e "${bold}Opening $file_export in $APP...${reset}"
|
||||
open -a "$APP" "$file_export"
|
||||
if [ -f "$file_export" ]; then
|
||||
echo -e "\n${bold}Opening $file_export in $APP...${reset}"
|
||||
open -a "$APP" "$file_export"
|
||||
fi
|
||||
else
|
||||
echo -e "${red}$APP was not found...${reset}"
|
||||
echo -e "\n${red}$APP was not found...${reset}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Move SRC file to trash
|
||||
# if [[ "$OSTYPE" == "linux-gnu" ]] && [ -x "$(command -v zenity)" ]; then
|
||||
# gvfs-trash filepath - gio trash some_file
|
||||
|
||||
|
||||
if [ "$trash" = true ] && [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
||||
osascript -e "tell application \"Finder\" to delete POSIX file \"${FILE}\"" >/dev/null
|
||||
fi
|
||||
if [ "$trash" = true ] && [[ "$OSTYPE" == "linux-gnu"* ]] && [[ $(command -v gio) != "" ]]; then
|
||||
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
||||
gio trash "$FILE" >/dev/null
|
||||
else
|
||||
echo -e "\n${italic}Move ${filename} to trash...${reset}"
|
||||
fi
|
||||
|
||||
|
||||
echo ""
|
||||
((count++))
|
||||
|
||||
else
|
||||
echo -e "\n${green}$file_export already transcoded !${reset}\n"
|
||||
|
||||
fi
|
||||
|
||||
FILESIZE=
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
||||
if [ "$count" -eq 0 ]; then
|
||||
echo -e "\n${red}No file to transcode !${reset}"
|
||||
else
|
||||
echo -e "\n${green}${count} files successfully transcoded !${reset}"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user