auto_sort now working
This commit is contained in:
17
auto_mkvmerge.desktop
Normal file → Executable file
17
auto_mkvmerge.desktop
Normal file → Executable file
@@ -1,7 +1,18 @@
|
|||||||
#!/usr/bin/env xdg-open
|
|
||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Name=auto_mkvmerge
|
Comment[de_DE]=
|
||||||
Exec=sh -e -c "exec \\"\\$(dirname \\"\\$0\\")/bin/auto_mkvmerge.sh\\"" %k
|
Comment=
|
||||||
|
Exec=sh -e -c 'exec "\\$(dirname "\\$0")/bin/auto_mkvmerge.sh"' %k
|
||||||
|
GenericName[de_DE]=
|
||||||
|
GenericName=
|
||||||
Icon=mkvmerge
|
Icon=mkvmerge
|
||||||
|
MimeType=
|
||||||
|
Name[de_DE]=auto_mkvmerge
|
||||||
|
Name=auto_mkvmerge
|
||||||
|
Path=
|
||||||
|
PrefersNonDefaultGPU=false
|
||||||
|
StartupNotify=true
|
||||||
Terminal=true
|
Terminal=true
|
||||||
|
TerminalOptions=
|
||||||
Type=Application
|
Type=Application
|
||||||
|
X-KDE-SubstituteUID=false
|
||||||
|
X-KDE-Username=
|
||||||
|
|||||||
18
auto_sort.desktop
Executable file
18
auto_sort.desktop
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Comment[de_DE]=
|
||||||
|
Comment=
|
||||||
|
Exec=sh -e -c 'exec "$(dirname "$0")/bin/auto_sort.sh"' %k
|
||||||
|
GenericName[de_DE]=
|
||||||
|
GenericName=
|
||||||
|
Icon=mkvmerge
|
||||||
|
MimeType=
|
||||||
|
Name[de_DE]=auto_mkvmerge
|
||||||
|
Name=auto_mkvmerge
|
||||||
|
Path=
|
||||||
|
PrefersNonDefaultGPU=false
|
||||||
|
StartupNotify=true
|
||||||
|
Terminal=true
|
||||||
|
TerminalOptions=
|
||||||
|
Type=Application
|
||||||
|
X-KDE-SubstituteUID=false
|
||||||
|
X-KDE-Username=
|
||||||
215
bin/auto_sort.sh
Normal file → Executable file
215
bin/auto_sort.sh
Normal file → Executable file
@@ -3,47 +3,56 @@
|
|||||||
# global variables
|
# global variables
|
||||||
declare -a video_file_list
|
declare -a video_file_list
|
||||||
settings_file="./settings.ini"
|
settings_file="./settings.ini"
|
||||||
|
ffprobe_path="/usr/bin/ffprobe"
|
||||||
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 zum Extrahieren der Sprachen und Audio-Codec für alle Audio-Spuren
|
||||||
|
extract_audio_languages_and_codecs() {
|
||||||
|
local file=$1
|
||||||
|
# Führe ffprobe aus und extrahiere die Streams
|
||||||
|
ffprobe_json=$("$ffprobe_path" -v error -show_streams -of json "$file")
|
||||||
|
|
||||||
# Funktion, um den kleinsten gemeinsamen übergeordneten Ordner zu finden
|
# Durchlaufe alle Audio-Streams und extrahiere Sprache und Codec
|
||||||
find_common_parent() {
|
audio_streams=()
|
||||||
local common_parent
|
while IFS= read -r audio_stream; do
|
||||||
local first_file=true
|
stream_index=$(echo "$audio_stream" | jq -r '.index')
|
||||||
|
codec_name=$(echo "$audio_stream" | jq -r '.codec_name')
|
||||||
|
language=$(echo "$audio_stream" | jq -r '.tags.language')
|
||||||
|
|
||||||
# Durchlaufe alle übergebenen Dateien
|
# Format für jede Audio-Spur: [index-codec_language]
|
||||||
for file in "$@"; do
|
audio_streams+=("[$codec_name"_"$language]")
|
||||||
# Überprüfe, ob die Datei existiert und eine Datei ist
|
done < <(echo "$ffprobe_json" | jq -c '.streams[] | select(.codec_type == "audio")')
|
||||||
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
|
# Rückgabe des Arrays der Audio-Streams
|
||||||
if [ "$first_file" = true ]; then
|
echo "${audio_streams[@]}"
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Funktion zum Extrahieren der Sprachen und "forced"-Tags für alle Untertitel-Spuren
|
||||||
|
extract_subtitle_languages_and_forced_tags() {
|
||||||
|
local file=$1
|
||||||
|
# Führe ffprobe aus und extrahiere die Streams
|
||||||
|
ffprobe_json=$("$ffprobe_path" -v error -show_streams -of json "$file")
|
||||||
|
|
||||||
|
# Durchlaufe alle Untertitel-Streams und extrahiere Sprache und Forced-Tag
|
||||||
|
subtitle_streams=()
|
||||||
|
while IFS= read -r subtitle_stream; do
|
||||||
|
stream_index=$(echo "$subtitle_stream" | jq -r '.index')
|
||||||
|
language=$(echo "$subtitle_stream" | jq -r '.tags.language')
|
||||||
|
# Überprüfe sowohl das Forced-Tag in "tags" als auch das Forced-Flag in "disposition"
|
||||||
|
forced=$(echo "$subtitle_stream" | jq -r '.tags.forced // empty')
|
||||||
|
forced_flag=$(echo "$subtitle_stream" | jq -r '.disposition.forced')
|
||||||
|
|
||||||
|
# Wenn das "forced"-Tag existiert, berücksichtige es
|
||||||
|
if [[ "$forced" == "1" || "$forced_flag" == "1" ]]; then
|
||||||
|
subtitle_streams+=("[forced_$language]")
|
||||||
|
fi
|
||||||
|
subtitle_streams+=("[$language]")
|
||||||
|
done < <(echo "$ffprobe_json" | jq -c '.streams[] | select(.codec_type == "subtitle")')
|
||||||
|
|
||||||
|
# Rückgabe des Arrays der Untertitel-Streams
|
||||||
|
echo "${subtitle_streams[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
get_user_variables_from_ini_file() {
|
get_user_variables_from_ini_file() {
|
||||||
|
|
||||||
@@ -69,97 +78,83 @@ get_user_variables_from_ini_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
relativ_to_fullpath() {
|
relativ_to_fullpath() {
|
||||||
|
|
||||||
local path="$1"
|
local path="$1"
|
||||||
scriptpath="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
scriptpath="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
|
||||||
|
|
||||||
|
# Entferne doppelte Slashes, bevor der Pfad weiterverarbeitet wird
|
||||||
|
path=$(echo "$path" | sed 's|/+|/|g')
|
||||||
|
|
||||||
if [ ! -e "$path" ]; then
|
if [ ! -e "$path" ]; then
|
||||||
pathfull=$(realpath "$(dirname "$scriptpath")/$path")
|
pathfull=$(realpath "$(dirname "$scriptpath")/$path" 2>/dev/null)
|
||||||
else
|
else
|
||||||
pathfull=$path
|
pathfull=$(realpath "$path" 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "$pathfull"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
main(){
|
||||||
|
|
||||||
|
get_user_variables_from_ini_file
|
||||||
|
|
||||||
|
output_dir="$input_folder/[0] Sort"
|
||||||
|
# Entferne doppelte Slashes
|
||||||
|
output_dir=$(echo "$output_dir" | sed 's|//|/|g')
|
||||||
|
|
||||||
|
|
||||||
|
echo "output_dir: '$output_dir'"
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p "$output_dir"
|
||||||
|
|
||||||
|
# Durchlaufe alle Videodateien im Eingabeverzeichnis rekursiv
|
||||||
|
find "$input_folder" -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" \) | while IFS= read -r file; do
|
||||||
|
# Überspringe Dateien, die "-sample" im Dateinamen haben
|
||||||
|
if [[ "$file" == *"-sample"* ]]; then
|
||||||
|
echo "Überspringe Datei '$file' (wegen '-sample' im Dateinamen)"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extrahiere die Audio-Spuren, Sprache und Codec
|
||||||
|
audio_streams=$(extract_audio_languages_and_codecs "$file")
|
||||||
|
|
||||||
|
# Extrahiere die Untertitel-Spuren, Sprache und "forced"-Tag
|
||||||
|
subtitle_streams=$(extract_subtitle_languages_and_forced_tags "$file")
|
||||||
|
|
||||||
|
# Wenn keine Audio- oder Untertitel-Spuren vorhanden sind, überspringe die Datei
|
||||||
|
if [ -z "$audio_streams" ] && [ -z "$subtitle_streams" ]; then
|
||||||
|
echo "Keine Audio- oder Untertitel-Spuren in '$file'. Überspringe."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Kombiniere die Audio- und Untertitel-Streams mit einem | nur, wenn subtitle_streams nicht leer ist
|
||||||
|
if [ -z "$subtitle_streams" ]; then
|
||||||
|
combined_streams="$audio_streams"
|
||||||
|
else
|
||||||
|
combined_streams="${audio_streams} | ${subtitle_streams}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generiere den Ordnernamen basierend auf den kombinierten Streams
|
||||||
|
folder_name=$(echo "$combined_streams" | tr ' ' ' ')
|
||||||
|
|
||||||
|
# Zielordner für diese Kombination erstellen
|
||||||
|
target_folder="$output_dir/$folder_name"
|
||||||
|
mkdir -p "$target_folder"
|
||||||
|
|
||||||
|
# Datei in den entsprechenden Ordner verschieben
|
||||||
|
mv "$file" "$target_folder/"
|
||||||
|
echo "Verschiebe '$file' nach '$target_folder/'"
|
||||||
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Main
|
||||||
|
main
|
||||||
|
|
||||||
|
|
||||||
|
$SHELL
|
||||||
_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
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user