The contents of my move_video.sh: Because I may rip a bunch of new blue rays and making a directory for each new movie is a pain in the ass. Select the videos you want, click the menu selection, and Thunar will make a directory with each movie name and move the appropriate file into the new directory. Then you can move all that into your Emby Library.
#!/bin/bash
#
#for i in *.mkv *.avi *.mp4; do
# if [[ “$i” != “*” && “$i” != “.” && “$i” != “..” ]]; then
# mkdir -p “${i%.*}”;
# mv “$i” “${i%.*}”;
# fi
#done
#
#!/bin/bash
# Script: organize_emby_movies.sh
# — CONFIGURATION —
# Define all recognized video extensions (lowercase, no dots)
VALID_EXTENSIONS=(“mkv” “avi” “mp4” “mov” “mts” “webm” “flv”)
LOG_FILE=”/tmp/thunar_organize_log.txt”
# ———————
# Loop through ALL selected files passed by Thunar (%F)
for INPUT_FILE in “$@”; do
# 1. Get the directory and filename components
OUTPUT_DIR_ORIGINAL=$(dirname “$INPUT_FILE”)
INPUT_BASENAME=$(basename — “$INPUT_FILE”)
# Extract the file extension and convert it to lowercase for reliable checking
FILE_EXTENSION=”${INPUT_BASENAME##*.}”
FILE_EXTENSION_LOWER=$(echo “$FILE_EXTENSION” | tr ‘[:upper:]’ ‘[:lower:]’)
# 2. Check if the file has a valid video extension
if [[ ” ${VALID_EXTENSIONS[@]} ” =~ ” ${FILE_EXTENSION_LOWER} ” ]]; then
# Strip the extension to get the directory name (e.g., Movie Name)
DIRECTORY_NAME=”${INPUT_BASENAME%.*}”
# Define the target subdirectory path
TARGET_SUBDIR=”$OUTPUT_DIR_ORIGINAL/$DIRECTORY_NAME”
# 3. Create the directory and move the file
mkdir -p “$TARGET_SUBDIR”
mv “$INPUT_FILE” “$TARGET_SUBDIR/” 2> “$LOG_FILE”
# 4. Check status of the move operation (for logging)
MV_STATUS=$?
if [ $MV_STATUS -ne 0 ]; then
# If the move failed (e.g., permissions error), alert the user
mv “$LOG_FILE” “$OUTPUT_DIR_ORIGINAL/organization_error_log.txt”
zenity –error –text=”Failed to move: $INPUT_FILE. Check the log file.” –title=”Organization Error”
else
rm “$LOG_FILE” 2>/dev/null
fi
else
# Optional: Alert if a non-video file was selected
zenity –warning –text=”Skipping: ‘$INPUT_FILE’ is not a recognized video file.” –title=”Skipping File”
fi
done
# Final cleanup
if [ -f “$LOG_FILE” ]; then rm “$LOG_FILE” 2>/dev/null; fi
exit 0
No comments:
Post a Comment
Keep it nice.