From 9f4f08697a163a0bfe79278de858cb9f2666b620 Mon Sep 17 00:00:00 2001 From: Haffel Date: Sat, 6 Sep 2025 20:12:25 +0200 Subject: [PATCH] add a bunch of scripts --- .obsidian/app.json | 4 + .obsidian/appearance.json | 1 + .obsidian/core-plugins.json | 33 ++++ .obsidian/workspace.json | 183 ++++++++++++++++++++ add-prefix-to-file.md | 21 +++ auto-fill-missing-artist-tags.md | 50 ++++++ bring-files-up-one-dir.md | 11 ++ bulk-move.md | 14 ++ ffmpeg.md | 105 +++++++++++ filename-as-metadata-title.md | 18 ++ find-short-videos.md | 31 ++++ move-file-into-dir-with-same-name.md | 20 +++ move-files-to-year-and-month-dirs.md | 22 +++ print-all-files-and-folders.md | 41 +++++ recursively-extract-artist-from-filename.md | 31 ++++ regex-stuff.md | 89 ++++++++++ remove-n-chars-from-name.md | 51 ++++++ remove-timestamps.md | 18 ++ rename-nested-file-to-parent.md | 23 +++ 19 files changed, 766 insertions(+) create mode 100644 .obsidian/app.json create mode 100644 .obsidian/appearance.json create mode 100644 .obsidian/core-plugins.json create mode 100644 .obsidian/workspace.json create mode 100644 add-prefix-to-file.md create mode 100644 auto-fill-missing-artist-tags.md create mode 100644 bring-files-up-one-dir.md create mode 100644 bulk-move.md create mode 100644 ffmpeg.md create mode 100644 filename-as-metadata-title.md create mode 100644 find-short-videos.md create mode 100644 move-file-into-dir-with-same-name.md create mode 100644 move-files-to-year-and-month-dirs.md create mode 100644 print-all-files-and-folders.md create mode 100644 recursively-extract-artist-from-filename.md create mode 100644 regex-stuff.md create mode 100644 remove-n-chars-from-name.md create mode 100644 remove-timestamps.md create mode 100644 rename-nested-file-to-parent.md diff --git a/.obsidian/app.json b/.obsidian/app.json new file mode 100644 index 0000000..8c13e56 --- /dev/null +++ b/.obsidian/app.json @@ -0,0 +1,4 @@ +{ + "alwaysUpdateLinks": true, + "showUnsupportedFiles": true +} \ No newline at end of file diff --git a/.obsidian/appearance.json b/.obsidian/appearance.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.obsidian/appearance.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json new file mode 100644 index 0000000..0faa60d --- /dev/null +++ b/.obsidian/core-plugins.json @@ -0,0 +1,33 @@ +{ + "file-explorer": true, + "global-search": true, + "switcher": true, + "graph": true, + "backlink": true, + "canvas": true, + "outgoing-link": true, + "tag-pane": true, + "footnotes": false, + "properties": false, + "page-preview": true, + "daily-notes": true, + "templates": true, + "note-composer": true, + "command-palette": true, + "slash-command": false, + "editor-status": true, + "bookmarks": true, + "markdown-importer": false, + "zk-prefixer": false, + "random-note": false, + "outline": true, + "word-count": true, + "slides": false, + "audio-recorder": false, + "workspaces": false, + "file-recovery": true, + "publish": false, + "sync": true, + "bases": true, + "webviewer": false +} \ No newline at end of file diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json new file mode 100644 index 0000000..ad69b73 --- /dev/null +++ b/.obsidian/workspace.json @@ -0,0 +1,183 @@ +{ + "main": { + "id": "c14fb7788bb86e58", + "type": "split", + "children": [ + { + "id": "b277dc0ec57ac4e5", + "type": "tabs", + "children": [ + { + "id": "bd0227a0bc51fda3", + "type": "leaf", + "state": { + "type": "empty", + "state": {}, + "icon": "lucide-file", + "title": "New tab" + } + } + ] + } + ], + "direction": "vertical" + }, + "left": { + "id": "10ee71e8f52d892a", + "type": "split", + "children": [ + { + "id": "63a8cd2db9e08095", + "type": "tabs", + "children": [ + { + "id": "50dd7c7842ea0193", + "type": "leaf", + "state": { + "type": "file-explorer", + "state": { + "sortOrder": "alphabetical", + "autoReveal": false + }, + "icon": "lucide-folder-closed", + "title": "Files" + } + }, + { + "id": "96368e722c01fada", + "type": "leaf", + "state": { + "type": "search", + "state": { + "query": "", + "matchingCase": false, + "explainSearch": false, + "collapseAll": false, + "extraContext": false, + "sortOrder": "alphabetical" + }, + "icon": "lucide-search", + "title": "Search" + } + }, + { + "id": "ecb77e1599effc54", + "type": "leaf", + "state": { + "type": "bookmarks", + "state": {}, + "icon": "lucide-bookmark", + "title": "Bookmarks" + } + } + ] + } + ], + "direction": "horizontal", + "width": 300 + }, + "right": { + "id": "cf899824f83d0bec", + "type": "split", + "children": [ + { + "id": "5b1763d858d0e9ab", + "type": "tabs", + "children": [ + { + "id": "5a0c75072484915d", + "type": "leaf", + "state": { + "type": "backlink", + "state": { + "collapseAll": false, + "extraContext": false, + "sortOrder": "alphabetical", + "showSearch": false, + "searchQuery": "", + "backlinkCollapsed": false, + "unlinkedCollapsed": true + }, + "icon": "links-coming-in", + "title": "Backlinks" + } + }, + { + "id": "85c23228c3824809", + "type": "leaf", + "state": { + "type": "outgoing-link", + "state": { + "linksCollapsed": false, + "unlinkedCollapsed": true + }, + "icon": "links-going-out", + "title": "Outgoing links" + } + }, + { + "id": "b58ae060bc33155e", + "type": "leaf", + "state": { + "type": "tag", + "state": { + "sortOrder": "frequency", + "useHierarchy": true, + "showSearch": false, + "searchQuery": "" + }, + "icon": "lucide-tags", + "title": "Tags" + } + }, + { + "id": "502c9508500b0f41", + "type": "leaf", + "state": { + "type": "outline", + "state": { + "followCursor": false, + "showSearch": false, + "searchQuery": "" + }, + "icon": "lucide-list", + "title": "Outline" + } + } + ] + } + ], + "direction": "horizontal", + "width": 300, + "collapsed": true + }, + "left-ribbon": { + "hiddenItems": { + "switcher:Open quick switcher": false, + "graph:Open graph view": false, + "canvas:Create new canvas": false, + "daily-notes:Open today's daily note": false, + "templates:Insert template": false, + "command-palette:Open command palette": false, + "bases:Create new base": false + } + }, + "active": "50dd7c7842ea0193", + "lastOpenFiles": [ + "rename-nested-file-to-parent.md", + "remove-timestamps.md", + "remove-n-chars-from-name.md", + "remove-n-chars-from-name_handle-duplicates.md", + "recursively-extract-artist-from-filename.md", + "print-all-files-and-folders.md", + "print-all-files-and-folders-to-file.md", + "move-files-to-year-and-month-dirs.md", + "move-file-into-dir-with-same-name.md", + "move-file-in-dir-with-same-name.md", + "find-short-videos.md", + "filename-as-metadata-title.md", + "bulk-move.md", + "bring-files-up-one-dir.md", + "auto-fill-missing-artist-tags.md" + ] +} \ No newline at end of file diff --git a/add-prefix-to-file.md b/add-prefix-to-file.md new file mode 100644 index 0000000..48758ee --- /dev/null +++ b/add-prefix-to-file.md @@ -0,0 +1,21 @@ +# Prefix + +> Add prefix to files + +```bash +for f in *; do + if [ -f "$f" ]; then + mv "$f" "PREFIX - $f" + fi +done +``` + +--- + +> Add prefix to dirs + +```bash +for d in */ ; do + mv "$d" "PREFIX - $d" +done +``` diff --git a/auto-fill-missing-artist-tags.md b/auto-fill-missing-artist-tags.md new file mode 100644 index 0000000..862e702 --- /dev/null +++ b/auto-fill-missing-artist-tags.md @@ -0,0 +1,50 @@ +# Auto fill missing Artist/Title Tags + +```bash +#!/bin/bash + +DIRECTORY="/path/to/dir" +LOGFILE="/path/to/dir/logfile.log" + +artist_like_attributes=( "ARTISTS" "ARTIST SORT ORDER" "ALBUM ARTIST" "ALBUM ARTIST SORT ORDER" ) +title_like_attributes=( "ALBUM" ) + +find "$DIRECTORY" -type f \( -iname "*.flac" -o -iname "*.mp3" -o -iname "*.opus" \) | while IFS= read -r file; do + echo "Processing file: $file" >> $LOGFILE + + artist=$(ffprobe -v error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 "$file") + title=$(ffprobe -v error -show_entries format_tags=title -of default=noprint_wrappers=1:nokey=1 "$file") + + if [ -n "$artist" ]; then + metadata_to_set=() + + for attribute in "${artist_like_attributes[@]}"; do + value=$(ffprobe -v error -show_entries "format_tags=$attribute" -of default=noprint_wrappers=1:nokey=1 "$file") + + if [ -z "$value" ]; then + metadata_to_set+=(-metadata "$attribute=$artist") + fi + done + + for attribute in "${title_like_attributes[@]}"; do + value=$(ffprobe -v error -show_entries "format_tags=$attribute" -of default=noprint_wrappers=1:nokey=1 "$file") + + if [ -z "$value" ]; then + metadata_to_set+=(-metadata "$attribute=$title") + fi + done + + if [ ${#metadata_to_set[@]} -ne 0 ]; then + temp_file=$(dirname "$file")/temp_$(basename "$file") + + ffmpeg -i "$file" -c copy "${metadata_to_set[@]}" -y "$temp_file" && mv -f "$temp_file" "$file" + + if [ $? -eq 0 ]; then + echo "Successfully updated: $file" >> $LOGFILE + else + echo "FFmpeg failed for: $file" >> $LOGFILE + fi + fi + fi +done +``` diff --git a/bring-files-up-one-dir.md b/bring-files-up-one-dir.md new file mode 100644 index 0000000..03d5f5c --- /dev/null +++ b/bring-files-up-one-dir.md @@ -0,0 +1,11 @@ +# Bring files up one dir + +> Bring files up by one level from their nested dirs + +```bash +find . -mindepth 2 -type f \( -name "*.mkv" -o -name "*.mp4" -o -name "*.avi" \) -exec sh -c ' + for file do + mv -- "$file" "$(dirname "$file")/.." + done +' sh {} + +``` diff --git a/bulk-move.md b/bulk-move.md new file mode 100644 index 0000000..11c181b --- /dev/null +++ b/bulk-move.md @@ -0,0 +1,14 @@ +# Bulk Move + +```bash +#!/bin/bash + +INPUT_FILE="folders_and_files_to_move.txt" +DESTINATION_DIR="/path/to/dir" + +while read -r dir; do + mv "$dir" "$DESTINATION_DIR" +done < "$INPUT_FILE" + +echo "All specified directories have been moved to '$DESTINATION_DIR'" +``` diff --git a/ffmpeg.md b/ffmpeg.md new file mode 100644 index 0000000..90ee030 --- /dev/null +++ b/ffmpeg.md @@ -0,0 +1,105 @@ +# Ffmpeg + +> Convert mkv to gif +```bash +ffmpeg -i "input.mkv" -vf "fps=10,scale=320:-1:flags=lanczos" -c:v gif -f gif "output.gif" +``` + +```bash +ffmpeg -i "input.mkv" -vf "fps=30,scale=1920:-1:flags=lanczos" -c:v gif -f gif "output.gif" +``` + +--- + +> Convert mkv to gif and get rid of that pattern +```bash +ffmpeg -i "input.mkv" -vf palettegen palette.png +ffmpeg -i "input.mkv" -i palette.png -lavfi "fps=30,scale=1920:-1:flags=lanczos [x]; [x][1:v] paletteuse=dither=none" "output.gif" +``` + +--- + +> Convert mkv to mp4 +```bash +ffmpeg -i "input.mkv" -codec copy "output.mp4" +``` + +--- + +> Detect silence +```bash +ffmpeg -i "Song.flac" -af silencedetect=noise=-30dB:d=5 -f null - 2>&1 | grep 'silence_' +``` + +--- + +> Check tags +```bash +ffprobe -v error -show_entries format_tags -of default=noprint_wrappers=1 "Song.flac" +``` + +--- + +> Extract aac from avi +```bash +ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac +``` + +--- + +> Increase volume of mp3 +```bash +ffmpeg -i input.mp3 -af volume=1.5 output.mp3 +``` + +--- + +> Convert DTS to AAC +```bash +ffmpeg -i "Movie [DTS] [1080p].mp4" -c:v copy -c:a aac -b:a 256k "Movie [AAC] [1080p].mp4" +``` + +--- + +> Check for errors +```bash +ffprobe -v error -show_entries frame=pkt_pts_time -of csv=p=0 "input.mp4" > errors.log +ffmpeg -v error -i "output.mp4" -c copy -f null - 2> errors2.log +``` + +--- + +> Get audio channels + languages of a file +```bash +ffprobe -v error -select_streams a -show_entries stream=index,codec_type,channels,channel_layout,codec_name,codec_long_name:stream_tags=language -of default=noprint_wrappers=1 "input.mkv" +``` + +--- + +> Cut up to certain timestamp +```bash +ffmpeg -i "input.mkv" -to 01:37:49 -c copy -map 0 "output.mkv" +``` + +--- + +> Cut starting from specific timeframe +```bash +ffmpeg -i "input.mp4" -ss 00:05:28 -c copy -avoid_negative_ts 1 "output.mp4" +``` + +--- + +> Extract single frame within timeframe close to keyframe +```bash +ffmpeg -ss 00:02:07 -to 00:02:10 -i "input.mp4" -vf "select='eq(pict_type,PICT_TYPE_I)'" -vsync vfr thumbnail_%03d.png +``` + +--- + +> Extract single frame at specific timestamp +```bash +ffmpeg -ss 00:00:03 -i "input.mp4" -vf "select='eq(pict_type,PICT_TYPE_I)'" -frames:v 1 output.png +``` + +--- diff --git a/filename-as-metadata-title.md b/filename-as-metadata-title.md new file mode 100644 index 0000000..dca3587 --- /dev/null +++ b/filename-as-metadata-title.md @@ -0,0 +1,18 @@ +# Filename as metadata title + +> Set the title in the metadata of all mp4 files based on the respective filename + +```bash +for FILE_PATH in *.mp4; do + if [ ! -f "$FILE_PATH" ]; then + continue + fi + + BASE_NAME=$(basename "$FILE_PATH" .mp4) + TEMP_FILE="${FILE_PATH}_temp.mp4" + + ffmpeg -i "$FILE_PATH" -c copy -metadata title="$BASE_NAME" "$TEMP_FILE" && mv "$TEMP_FILE" "$FILE_PATH" +done + +echo "Metadata title set for all MP4 files in directory" +``` diff --git a/find-short-videos.md b/find-short-videos.md new file mode 100644 index 0000000..6295a08 --- /dev/null +++ b/find-short-videos.md @@ -0,0 +1,31 @@ +# Find short Videos + +```bash +#!/bin/bash + +DIR="/path/to/dir" +DURATION_THRESHOLD_SECONDS=300 +IGNORED_FOLDERS=("backdrops") +OUTPUT_FILE="short_video_dirs.txt" + +> "$OUTPUT_FILE" + +find . -type f -name "$DIR/*.mp4" | while read -r file; do + parent_dir=$(dirname "$file") + + for ignored_folder in "${IGNORED_FOLDERS[@]}"; do + if [[ "$parent_dir" == *"$ignored_folder"* ]]; then + continue 2 + fi + done + + length=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file") + length=$(printf "%.0f\n" "$length") + + if [ "$length" -lt "$DURATION_THRESHOLD_SECONDS" ]; then + grep -qxF "$parent_dir" "$OUTPUT_FILE" || echo "$parent_dir" >> "$OUTPUT_FILE" + fi +done + +echo "Operation complete. The list of parent directories has been saved to $OUTPUT_FILE." +``` diff --git a/move-file-into-dir-with-same-name.md b/move-file-into-dir-with-same-name.md new file mode 100644 index 0000000..991d9ea --- /dev/null +++ b/move-file-into-dir-with-same-name.md @@ -0,0 +1,20 @@ +# Move file into dir with same name + +> Move all mp4 files into a dir with the same name as the file + +```bash +#!/bin/bash + +find . -maxdepth 1 -type f -iname *.mp4 -exec bash -c ' + for file in "$@"; do + # Extract the base name without the extension + base="${file%.mp4}" + + # Create a new directory with the base name + mkdir -p "${base}" + + # Move the MP4 file into the newly created directory + mv "$file" "${base}/" + done +' bash {} + +``` diff --git a/move-files-to-year-and-month-dirs.md b/move-files-to-year-and-month-dirs.md new file mode 100644 index 0000000..83f0112 --- /dev/null +++ b/move-files-to-year-and-month-dirs.md @@ -0,0 +1,22 @@ +# Move files to year and month dirs + +> Extract date from folder name and move into year and month separated sub dirs + +```bash +#!/bin/bash + +for dir in */; do + if [[ -d "$dir" ]]; then + if [[ $dir =~ ([0-9]{4}-[0-9]{2}-[0-9]{2}) ]]; then + date=${BASH_REMATCH[1]} + year=${date:0:4} + month=${date:5:2} + + mkdir -p "$year/$month" + mv "$dir" "$year/$month/" + else + echo "The directory '$dir' does not contain a valid date." + fi + fi +done +``` diff --git a/print-all-files-and-folders.md b/print-all-files-and-folders.md new file mode 100644 index 0000000..f631697 --- /dev/null +++ b/print-all-files-and-folders.md @@ -0,0 +1,41 @@ +# Print all files and folders + +> Save all file and folder names in a directory to a file + +```bash +#!/bin/bash + +OUTPUT_FILE="directory_contents.txt" + +> "$OUTPUT_FILE" + +echo "Listing all files and folders in current dir" + +for item in /*; do + if [ -f "$item" ]; then + echo "$(basename "$item")" >> "$OUTPUT_FILE" + elif [ -d "$item" ]; then + echo "$(basename "$item")" >> "$OUTPUT_FILE" + fi +done + +echo "Contents have been written to $OUTPUT_FILE." +``` + +--- + +> Get all file and folder names in a directory + +```bash +#!/bin/bash + +echo "Listing all files and folders in current dir" + +for item in /*; do + if [ -f "$item" ]; then + echo "$(basename "$item")" + elif [ -d "$item" ]; then + echo "$(basename "$item")" + fi +done +``` diff --git a/recursively-extract-artist-from-filename.md b/recursively-extract-artist-from-filename.md new file mode 100644 index 0000000..e755345 --- /dev/null +++ b/recursively-extract-artist-from-filename.md @@ -0,0 +1,31 @@ +# Recursively extract artist from filename + +> Used to extract the first artist name, assuming it sits between the first " - " and second " - " + +```bash +#!/bin/sh + +SEARCH_DIR="/path/to/dir" +OUTPUT_FILE="artist_names.txt" + +cd "$SEARCH_DIR" || exit + +> "$OUTPUT_FILE" + +find . -type f -name '* - *' | while read -r file; do + intermediate_string=$(echo "$file" | sed -n 's/.* - \(.*\) - .*/\1/p') + + artist=$(echo "$intermediate_string" | \ + sed -e 's/ x .*//i' \ + -e 's/ X .*//i' \ + -e 's/ ft\. .*//i' \ + -e 's/ feat\. .*//i' \ + -e 's/ & .*//i' \ + -e 's/, .*//i' \ + -e 's/ + .*//i') + + echo "$artist" >> "$OUTPUT_FILE" +done + +cd - || exit +``` diff --git a/regex-stuff.md b/regex-stuff.md new file mode 100644 index 0000000..d248983 --- /dev/null +++ b/regex-stuff.md @@ -0,0 +1,89 @@ +# Regex Stuff + +> Remove everything from first `?` (including) in filenames recursively + +```bash +#!/bin/bash + +START_DIR="." + +find "$START_DIR" -type f -print0 | while IFS= read -r -d '' file; do + dir=$(dirname "$file") + base=$(basename "$file") + new_base="${base%%\?*}" + + if [[ "$base" != "$new_base" ]]; then + mv -n "$file" "${dir}/${new_base}" + fi +done + +echo "File renaming complete." +``` + +--- + +> Extract from strings in file + +```bash +grep -oP "href='\K[^']+?(?=')" "Bookmarks.html" > urls.txt +grep -oP "HREF=\"\K[^\"]+?(?=\")" "Bookmarks2.html" > urls2.txt +``` + +--- + +> Replace something in dir name + +```bash +search_string="REPLACE ME - " +replace_string="" + +for d in */ ; do + d="${d%/}" + + if [[ "$d" == *"$search_string"* ]]; then + new_d="${d/$search_string/$replace_string}" + + mv -- "$d" "$new_d" + fi +done +``` + +--- + +> Replace anywhere, case insensitive + +```bash +for f in *; do + if [ -f "$f" ]; then + newname=$(echo "$f" | sed 's/some\.string/A new String/gi') + + mv -- "$f" "$newname" + fi +done +``` + +--- + +> Replace something at beginning of filename + +```bash +for f in *; do + if [ -f "$f" ]; then + newname=$(echo "$f" | sed 's/^some\.string/A new String/') + mv -- "$f" "$newname" + fi +done +``` + +--- + +> Replace anywhere in filename + +```bash +for f in *; do + if [ -f "$f" ]; then + newname=$(echo "$f" | sed 's/BEFORE/After/gi') + mv -- "$f" "$newname" + fi +done +``` diff --git a/remove-n-chars-from-name.md b/remove-n-chars-from-name.md new file mode 100644 index 0000000..414f5d5 --- /dev/null +++ b/remove-n-chars-from-name.md @@ -0,0 +1,51 @@ +# Remove N chars from name + +```bash +#!/bin/bash + +TARGET_DIR="." +REMOVE_N_CHARS=8 + +for dir in "$TARGET_DIR/*/"; do + dir="${dir%/}" + + new_dir="${dir:$REMOVE_N_CHARS}" + + mv -- "$dir" "$new_dir" +done +``` + +--- + +```bash +#!/bin/bash + +TARGET_DIR="." +REMOVE_N_CHARS=8 + +generate_unique_dir_name() { + local base_name=$1 + local counter=2 + local new_name + + while true; do + new_name="${base_name}_${counter}" + if [[ ! -d "$new_name" ]]; then + echo "$new_name" + break + fi + ((counter++)) + done +} + +for dir in "$TARGET_DIR/*/"; do + dir="${dir%/}" + new_dir="${dir:$REMOVE_N_CHARS}" + + if [[ -d "$new_dir" ]]; then + new_dir=$(generate_unique_dir_name "$new_dir") + fi + + mv -- "$dir" "$new_dir" +done +``` diff --git a/remove-timestamps.md b/remove-timestamps.md new file mode 100644 index 0000000..9db274a --- /dev/null +++ b/remove-timestamps.md @@ -0,0 +1,18 @@ +# Remove timestamps + +> Remove timestamps from files and folders + +```bash +#!/bin/bash + +for file in [0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]*; do + if ! [[ $file =~ ^[0-9][0-9]-[0-9][0-9]-[0-9]{4}\ [0-9]{1,2}#[0-9]{2}\ (AM|PM)\ -\ ]]; then + continue + fi + + newname=$(echo "$file" | sed -E 's/^[0-9]{2}-[0-9]{2}-[0-9]{4} [0-9]{1,2}#[0-9]{2} (AM|PM) - //') + mv -- "$file" "$newname" +done + +echo "Files have been renamed." +``` diff --git a/rename-nested-file-to-parent.md b/rename-nested-file-to-parent.md new file mode 100644 index 0000000..c1600c0 --- /dev/null +++ b/rename-nested-file-to-parent.md @@ -0,0 +1,23 @@ +# Rename nested file to parent + +> Go through all folders, check if mp4 is in there. If so, rename the mp4 to the same as it's respective parent folder + +```bash +#!/bin/bash + +for dir in */; do + if [[ -d "$dir" ]]; then + dir_name="${dir%/}" + mp4_file=$(find "$dir" -maxdepth 1 -type f -name '*.mp4' | head -n 1) + + if [[ -n "$mp4_file" ]]; then + new_filename="${dir_name}.mp4" + + mv -n "$mp4_file" "${dir}/${new_filename}" + echo "Renamed '$mp4_file' to '${dir}/${new_filename}'" + else + echo "No .mp4 file found in $dir" + fi + fi +done +```