From d95563f3fac3b79e0f9bdc23fe4960ec4bd2895a Mon Sep 17 00:00:00 2001 From: Haffel Date: Fri, 24 Oct 2025 00:11:59 +0200 Subject: [PATCH] add scripts, fix formatting --- .obsidian/workspace.json | 52 +++++++++++++++------ ffmpeg.md | 7 +++ metadata-stuff.md | 68 ++++++++++++++++++++++++++++ move-file-into-dir-with-same-name.md | 2 +- regex-stuff.md | 14 ++++++ 5 files changed, 129 insertions(+), 14 deletions(-) diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 385abdf..1693631 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -10,14 +10,37 @@ { "id": "bd0227a0bc51fda3", "type": "leaf", + "pinned": true, "state": { - "type": "empty", - "state": {}, + "type": "markdown", + "state": { + "file": "rename-nested-file-to-parent.md", + "mode": "source", + "source": false + }, + "pinned": true, "icon": "lucide-file", - "title": "New tab" + "title": "rename-nested-file-to-parent" + } + }, + { + "id": "aad5fb65253dfe6f", + "type": "leaf", + "pinned": true, + "state": { + "type": "markdown", + "state": { + "file": "metadata-stuff.md", + "mode": "source", + "source": false + }, + "pinned": true, + "icon": "lucide-file", + "title": "metadata-stuff" } } - ] + ], + "currentTab": 1 } ], "direction": "vertical" @@ -90,6 +113,7 @@ "state": { "type": "backlink", "state": { + "file": "metadata-stuff.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -99,7 +123,7 @@ "unlinkedCollapsed": true }, "icon": "links-coming-in", - "title": "Backlinks" + "title": "Backlinks for metadata-stuff" } }, { @@ -148,8 +172,7 @@ } ], "direction": "horizontal", - "width": 300, - "collapsed": true + "width": 300 }, "left-ribbon": { "hiddenItems": { @@ -162,16 +185,22 @@ "bases:Create new base": false } }, - "active": "bd0227a0bc51fda3", + "active": "aad5fb65253dfe6f", "lastOpenFiles": [ + "rename-nested-file-to-parent.md", + "metadata-stuff.md", + "move-file-into-dir-with-same-name.md", + "ffmpeg.md", + "find-short-videos.md", + "bulk-move.md", + "regex-stuff.md", + "add-prefix-to-file.md", "usr-local-bin/setartist", "usr-local-bin/getresauto", "usr-local-bin/getres", "usr-local-bin/cutto", "usr-local-bin/cutfrom", "usr-local-bin", - "metadata-stuff.md", - "rename-nested-file-to-parent.md", "remove-timestamps.md", "remove-n-chars-from-name.md", "remove-n-chars-from-name_handle-duplicates.md", @@ -179,11 +208,8 @@ "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" ] diff --git a/ffmpeg.md b/ffmpeg.md index 90ee030..dea04ab 100644 --- a/ffmpeg.md +++ b/ffmpeg.md @@ -26,6 +26,13 @@ ffmpeg -i "input.mkv" -codec copy "output.mp4" --- +> Convert flac to mp3 +```bash +ffmpeg -i "input.flac" -ab 320k "output.mp3" +``` + +--- + > Detect silence ```bash ffmpeg -i "Song.flac" -af silencedetect=noise=-30dB:d=5 -f null - 2>&1 | grep 'silence_' diff --git a/metadata-stuff.md b/metadata-stuff.md index b565a6d..134c657 100644 --- a/metadata-stuff.md +++ b/metadata-stuff.md @@ -21,6 +21,8 @@ echo "All paths have been stored in $OUTPUT_FILE" > Auto fill missing Artist/Title Tags based on existing tags +> This throws some weird errors where it says "mnt/path/to/dir.flac not found" (note the missing / at the beginning of the path). Happens with both absolute and relative. Doesn't throw for every file. Rerun the script until no more errors and files missing to process + ```bash #!/bin/bash @@ -95,6 +97,33 @@ echo "Metadata title set for all MP4 files in directory" --- +> Set artist recursively + +```bash +ARTIST="Artist Name" + +for DIR in */ ; do + if [ -d "$DIR" ]; then + for FILE_PATH in "$DIR"*.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 artist="$ARTIST" "$TEMP_FILE" && mv "$TEMP_FILE" "$FILE_PATH" + done + fi +done + +echo "Metadata artist set for all MP4 files in directory" +``` + + +--- + + > Set the title in the metadata of all mp4 files based on the respective filename, recursively ```bash @@ -119,6 +148,45 @@ echo "Metadata title set for all MP4 files in subdirectories." ``` + +```bash +#!/bin/bash + +for DIR in */ ; do + if [ -d "$DIR" ]; then + for FILE_PATH in "$DIR"*.mp4; do + if [ ! -f "$FILE_PATH" ]; then + continue + fi + + # Get base name without extension + BASE_NAME=$(basename "$FILE_PATH" .mp4) + TEMP_FILE="${FILE_PATH%.*}_temp.mp4" + + # Fetch current comment metadata + CURRENT_COMMENT=$(ffprobe -v error -show_entries format_tags=comment -of default=noprint_wrappers=1:nokey=1 "$FILE_PATH") + CURRENT_TITLE=$(ffprobe -v error -show_entries format_tags=title -of default=noprint_wrappers=1:nokey=1 "$FILE_PATH") + + echo "Current Comment: $CURRENT_COMMENT" + echo "Current Title: $CURRENT_TITLE" + + # If there's no current comment, set it to the old base name + # Otherwise, append the old base name to the current comment + if [ -z "$CURRENT_COMMENT" ]; then + NEW_COMMENT=$BASE_NAME + else + NEW_COMMENT="${CURRENT_COMMENT}; Old Title: ${CURRENT_TITLE}" + fi + + # Use ffmpeg to set title and update the comment + ffmpeg -i "$FILE_PATH" -c copy -metadata title="$BASE_NAME" -metadata comment="$NEW_COMMENT" "$TEMP_FILE" && mv -f "$TEMP_FILE" "$FILE_PATH" + done + fi +done + +echo "Metadata title and comment updated for all MP4 files in subdirectories." +``` + --- diff --git a/move-file-into-dir-with-same-name.md b/move-file-into-dir-with-same-name.md index 991d9ea..a86409e 100644 --- a/move-file-into-dir-with-same-name.md +++ b/move-file-into-dir-with-same-name.md @@ -5,7 +5,7 @@ ```bash #!/bin/bash -find . -maxdepth 1 -type f -iname *.mp4 -exec bash -c ' +find . -maxdepth 1 -type f -iname "*.mp4" -exec bash -c ' for file in "$@"; do # Extract the base name without the extension base="${file%.mp4}" diff --git a/regex-stuff.md b/regex-stuff.md index 304f92e..45f3d1c 100644 --- a/regex-stuff.md +++ b/regex-stuff.md @@ -135,3 +135,17 @@ done echo "Extraction complete. Content saved to $OUTPUT_FILE." ``` + +--- + + +> Replace first 4 characters + +```bash +for f in * ; do + if [[ -f "$f" ]]; then + new_f="${f:4}" + mv -- "$f" "$new_f" + fi +done +```