51 lines
1.5 KiB
Bash
51 lines
1.5 KiB
Bash
#!/bin/bash
|
|
|
|
# Step 1: Prompt user for Year and Tag [7][9]
|
|
read -p "Enter Year: " user_year
|
|
read -p "Enter Tag: " user_tag
|
|
|
|
# Process the first MP4 file found in the current directory
|
|
for file in *.mp4; do
|
|
if [ -f "$file" ]; then
|
|
# Extract Title and Resolution (Height) using ExifTool [4][5]
|
|
# -s3 returns just the value of the tag
|
|
title=$(exiftool -s3 -Title "$file")
|
|
|
|
# If the internal Title tag is empty, fall back to the filename [5]
|
|
if [ -z "$title" ]; then
|
|
title="${file%.*}"
|
|
fi
|
|
|
|
# Extracting image height for pixel count (e.g., 1080) [4]
|
|
height=$(exiftool -s3 -ImageHeight "$file")
|
|
if [ -n "$height" ]; then
|
|
pixel="${height}p"
|
|
else
|
|
pixel="UnknownRes"
|
|
fi
|
|
|
|
# Construct the new base name (without extension)
|
|
new_base_name="${title} ${user_year} ${pixel} ${user_tag}"
|
|
|
|
# Step 2: Rename the file [5][11]
|
|
new_file_name="${new_base_name}.mp4"
|
|
mv "$file" "$new_file_name"
|
|
|
|
# Step 3: Rename the parent directory [1][2]
|
|
# Identify current directory info
|
|
current_dir_path=$(pwd)
|
|
parent_dir=$(dirname "$current_dir_path")
|
|
current_folder_name=$(basename "$current_dir_path")
|
|
|
|
# Move to the parent directory to rename the 'root' folder
|
|
cd "$parent_dir" || exit
|
|
mv "$current_folder_name" "$new_base_name"
|
|
|
|
echo "Successfully renamed file to: $new_file_name"
|
|
echo "Successfully renamed folder to: $new_base_name"
|
|
|
|
# Exit after processing the first video file
|
|
break
|
|
fi
|
|
done
|