#!/bin/bash # global variables declare -a video_file_list settings_file="./settings.ini" get_user_variables_from_ini_file #save all mp4 and mkv file paths in video_file_list array mapfile -t video_file_list < <(find "$input_folder" -type f \( -name "*.mp4" -o -name "*.mkv" -o -name "*.avi" \) | sort) # Funktion, um den kleinsten gemeinsamen übergeordneten Ordner zu finden find_common_parent() { local common_parent local first_file=true # Durchlaufe alle übergebenen Dateien for file in "$@"; do # Überprüfe, ob die Datei existiert und eine Datei ist if [ -f "$file" ]; then # Bestimme den Ordner der Datei file_dir=$(dirname "$file") # Wenn dies die erste Datei ist, setze den gemeinsamen übergeordneten Ordner auf den Ordner dieser Datei if [ "$first_file" = true ]; then common_parent="$file_dir" first_file=false else # Andernfalls bestimme den gemeinsamen übergeordneten Ordner zwischen dem aktuellen und dem bisherigen common_parent=$(realpath --relative-to="$common_parent" "$file_dir") fi else echo "Datei existiert nicht: $file" return 1 fi done # Gib den gemeinsamen übergeordneten Ordner zurück echo "$common_parent" } get_user_variables_from_ini_file() { # get absolut path of the ini file settings_file=$(relativ_to_fullpath "$settings_file") # abort script if settings file can't be found if [ ! -e "$settings_file" ]; then _exit 1 "Settingsfile not found at: "$settings_file fi # read ini values input_folder=$(sed -nr "/^\[pathes\]/ { :l /^input_folder[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") output_folder=$(sed -nr "/^\[pathes\]/ { :l /^output_folder[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") jsonfile_path=$(sed -nr "/^\[pathes\]/ { :l /^jsonfile_path[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") mode=$(sed -nr "/^\[mode\]/ { :l /^mode[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") mkvmerge=$(sed -nr "/^\[mkvmerge\]/ { :l /^mkvmerge[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") notification_text=$(sed -nr "/^\[notification_text\]/ { :l /^notification_text[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") nofification_audio=$(sed -nr "/^\[nofification_audio\]/ { :l /^nofification_audio[ ]*=/ { s/[^=]*=[ ]*//; p; q;}; n; b l;}" "$settings_file") } relativ_to_fullpath() { local path="$1" scriptpath="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" if [ ! -e "$path" ]; then pathfull=$(realpath "$(dirname "$scriptpath")/$path") else pathfull=$path fi } _exit(){ #get the exit message local error_state="$1" local error_msg="$2" local scriptpath="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" #script stopted with errors if [ "$error_state" = 1 ]; then #echo output echo "────────────────────────────────────────────────────────────────" echo -e "${WHITE_ON_RED} Error ${NC}" echo echo -e "${RED}$error_msg${NC}" echo "────────────────────────────────────────────────────────────────" #notification_text if [ "$notification_text" = "on" ]; then notify-send --urgency=critical "Auto MKVMerge Warning" "$error_msg" fi #nofification_audio if [ "$nofification_audio" = "beep" ]; then playsound_speaker_sound 1500 150 playsound_speaker_sound 1500 150 playsound_speaker_sound 1500 150 elif [ "$nofification_audio" = "voice" ]; then spd-say "Auto MKVMerge Error" elif [ "$nofification_audio" = "file" ]; then aplay "$scriptpath/error.wav" > /dev/null 2>&1 fi #exit the script echo read -n 1 -s -r -p "Press any key to exit" exit fi #normal exit if [ "$error_state" = 0 ]; then #echo output echo "────────────────────────────────────────────────────────────────" echo -e "${BLACK_ON_WHITE} Finished! ${NC}" echo "────────────────────────────────────────────────────────────────" #notification_text if [ "$notification_text" = "on" ]; then notify-send --urgency=normal "Auto MKVMerge" "Finished!" fi #nofification_audio if [ "$nofification_audio" = "beep" ]; then playsound_speaker_sound 200 200 playsound_speaker_sound 400 200 elif [ "$nofification_audio" = "voice" ]; then spd-say "Auto MKVMerge ist fertig" elif [ "$nofification_audio" = "file" ]; then aplay "$scriptpath/done.wav" > /dev/null 2>&1 fi #exit the script echo read -n 1 -s -r -p "Press any key to exit" exit fi #exit the script echo read -n 1 -s -r -p "Press any key to exit" exit }