diff --git a/filename-as-metadata-title.md b/filename-as-metadata-title.md index 6d4ecec..b196185 100644 --- a/filename-as-metadata-title.md +++ b/filename-as-metadata-title.md @@ -24,28 +24,20 @@ echo "Metadata title set for all MP4 files in directory" ```bash #!/bin/bash -# Loop through directories one level deep for DIR in */ ; do - # Ensure it's a directory if [ -d "$DIR" ]; then - # Loop through mp4 files in this subdirectory for FILE_PATH in "$DIR"*.mp4; do - # Check if the file exists if [ ! -f "$FILE_PATH" ]; then continue fi - # Extract basename without the path and extension BASE_NAME=$(basename "$FILE_PATH" .mp4) - - # Define a temp file path TEMP_FILE="${FILE_PATH%.*}_temp.mp4" - # Set the metadata title using ffmpeg and then replace the original file ffmpeg -i "$FILE_PATH" -c copy -metadata title="$BASE_NAME" "$TEMP_FILE" && mv -f "$TEMP_FILE" "$FILE_PATH" done fi done echo "Metadata title set for all MP4 files in subdirectories." -``` \ No newline at end of file +``` diff --git a/rename-nested-file-to-parent.md b/rename-nested-file-to-parent.md index dccd409..b0f4aae 100644 --- a/rename-nested-file-to-parent.md +++ b/rename-nested-file-to-parent.md @@ -31,27 +31,16 @@ done ```bash #!/bin/bash -# Loop through each subdirectory in the current directory for dir in */; do - # Check if it's a directory if [[ -d "$dir" ]]; then - # Find the first .mp4 file in the directory mp4_file=$(find "$dir" -maxdepth 1 -type f -name '*.mp4' | head -n 1) - # If a .mp4 file is found if [[ -n "$mp4_file" ]]; then - # Get the file's basename without path and extension mp4_base_name="$(basename "${mp4_file}" .mp4)" - - # Trim the trailing slash from the directory name trimmed_dir_name="${dir%/}" - - # New directory name will be the name of the .mp4 file new_dir_name="${mp4_base_name}" - # Rename the directory, only if new directory name is different than the original if [[ "$trimmed_dir_name" != "$new_dir_name" ]]; then - # Check if target directory name already exists if [[ ! -d "$new_dir_name" ]]; then mv -n "$dir" "$new_dir_name" echo "Renamed directory '$dir' to '$new_dir_name'"