#!/bin/bash # # to categorize named folders # # Check if tvshow_categorize_name is available if ! command -v tvshow_categorize_name &> /dev/null; then echo "tvshow_categorize_name command not found" exit 1 fi # Find and process directories find . -maxdepth 1 -type d -name "[^.]*.*E[0-9][0-9]*" -print0 | while IFS= read -r -d '' dir; do # Get the name from tvshow_categorize_name NAME="$(tvshow_categorize_name "$dir")" # Check if the name was successfully retrieved if [[ -z "$NAME" ]]; then echo "Failed to categorize $dir" continue fi echo "$dir -> $NAME" # Create the destination directory if it doesn't exist if [[ ! -d "$NAME" ]]; then sudo mkdir -p "$NAME" fi # Move the video files to the categorized directory sudo mv "$dir/"*.mp4 "$NAME" 2>/dev/null sudo mv "$dir/"*.mkv "$NAME" 2>/dev/null # Check if the move was successful before removing the directory if [[ $? -eq 0 ]]; then sudo rm -rf "$dir" else echo "Failed to move files from $dir to $NAME" fi done