diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 0afc48c..385abdf 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -164,6 +164,12 @@ }, "active": "bd0227a0bc51fda3", "lastOpenFiles": [ + "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", diff --git a/usr-local-bin/cutfrom b/usr-local-bin/cutfrom new file mode 100644 index 0000000..ca1f9bb --- /dev/null +++ b/usr-local-bin/cutfrom @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 01:37:18" + exit 1 +fi + +VIDEO_FILE=$(ls *.mp4 | head -n 1) + +if [ -z "$VIDEO_FILE" ]; then + echo "No .mp4 files found in the current directory." + exit 1 +fi + +echo "Video File: ${VIDEO_FILE}" + +TIMESTAMP="$1" +OUTPUT_DIR="target" +OUTPUT_FILE="${OUTPUT_DIR}/${VIDEO_FILE}" + +mkdir -p "${OUTPUT_DIR}" + +ffmpeg -i "${VIDEO_FILE}" -ss "${TIMESTAMP}" -c copy -avoid_negative_ts 1 "${OUTPUT_FILE}" + +echo "Cut complete! Output is in ${OUTPUT_FILE}" diff --git a/usr-local-bin/cutto b/usr-local-bin/cutto new file mode 100644 index 0000000..6164bd1 --- /dev/null +++ b/usr-local-bin/cutto @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 01:37:18" + exit 1 +fi + +VIDEO_FILE=$(ls *.mp4 | head -n 1) + +if [ -z "$VIDEO_FILE" ]; then + echo "No .mp4 files found in the current directory." + exit 1 +fi + +echo "Video File: ${VIDEO_FILE}" + +TIMESTAMP="$1" +OUTPUT_DIR="target" +OUTPUT_FILE="${OUTPUT_DIR}/${VIDEO_FILE}" + +mkdir -p "${OUTPUT_DIR}" + +ffmpeg -i "${VIDEO_FILE}" -to "${TIMESTAMP}" -c copy -map 0 "${OUTPUT_FILE}" + +echo "Cut complete! Output is in ${OUTPUT_FILE}" diff --git a/usr-local-bin/getres b/usr-local-bin/getres new file mode 100644 index 0000000..40a4825 --- /dev/null +++ b/usr-local-bin/getres @@ -0,0 +1,49 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 video_file" + exit 1 +fi + +VIDEO_FILE="$1" + +RESOLUTION=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$VIDEO_FILE") + +HEIGHT=$(echo $RESOLUTION | cut -d'x' -f2) + +classify_resolution() { + local HEIGHT="$1" + + # Classify based on height + if (( HEIGHT >= 4320 )); then + echo "4320p" + elif (( HEIGHT >= 2160 )); then + echo "2160p" + elif (( HEIGHT >= 1080 )); then + echo "1080p" + elif (( HEIGHT >= 720 )); then + echo "720p" + elif (( HEIGHT >= 480 )); then + echo "480p" + elif (( HEIGHT >= 360 )); then + echo "360p" + elif (( HEIGHT >= 240 )); then + echo "240p" + else + echo "Unknown resolution" + fi +} + +CLASSIFICATION=$(classify_resolution "$HEIGHT") + +echo "Resolution: $RESOLUTION" +echo "Resolution classification: $CLASSIFICATION" + +BASENAME=$(basename "$VIDEO_FILE") +BASENAME_NO_EXT="${BASENAME%.*}" +EXTENSION="${BASENAME##*.}" +NEW_FILENAME="${BASENAME_NO_EXT} [${CLASSIFICATION}].${EXTENSION}" + +echo "Renaming '$VIDEO_FILE' to '$NEW_FILENAME'" + +mv "$VIDEO_FILE" "$NEW_FILENAME" diff --git a/usr-local-bin/getresauto b/usr-local-bin/getresauto new file mode 100644 index 0000000..82b5441 --- /dev/null +++ b/usr-local-bin/getresauto @@ -0,0 +1,62 @@ +#!/bin/bash + +classify_resolution() { + local HEIGHT="$1" + + case "$HEIGHT" in + [7-9]*|6[4-9]*) + echo "4320p" + ;; + [3-5]*|21[6-9]*|2[2-9]*) + echo "2160p" + ;; + 1[0-8]*|19[0-7]*) + echo "1080p" + ;; + [8-9]*|7[0-1]*) + echo "720p" + ;; + 4[8-9]*|[5-6]*) + echo "480p" + ;; + 3[6-9]*) + echo "360p" + ;; + 2[4-9]*) + echo "240p" + ;; + *) + echo "Unknown" + ;; + esac +} + +read -p "This will automatically classify and rename the resolution for all nested files in the current dir. Continue? [Y/n] " -n 1 -r +echo + +if [[ $REPLY =~ ^[Yy]$ ]]; then + find . -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.wmv" \) -print0 | while IFS= read -r -d '' VIDEO_FILE; do + + echo "-----------------------------" + echo "Processing file: $VIDEO_FILE" + + RESOLUTION=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 -i "$VIDEO_FILE") + HEIGHT=$(echo $RESOLUTION | cut -d'x' -f2) + CLASSIFICATION=$(classify_resolution "$HEIGHT") + + echo "Resolution: $RESOLUTION" + echo "Resolution classification: $CLASSIFICATION" + + BASENAME=$(basename -- "$VIDEO_FILE") + DIRNAME=$(dirname -- "$VIDEO_FILE") + BASENAME_NO_EXT="${BASENAME%.*}" + EXTENSION="${BASENAME##*.}" + NEW_FILENAME="${BASENAME_NO_EXT} [${CLASSIFICATION}].${EXTENSION}" + + echo -e "Renaming: $VIDEO_FILE -> $DIRNAME/$NEW_FILENAME" + + mv "$VIDEO_FILE" "$DIRNAME/$NEW_FILENAME" + done +else + echo "Batch renaming cancelled by user." +fi diff --git a/usr-local-bin/setartist b/usr-local-bin/setartist new file mode 100644 index 0000000..14df535 --- /dev/null +++ b/usr-local-bin/setartist @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 'Artist Name'" + exit 1 +fi + +ARTIST_NAME="$1" +VIDEO_FILE=$(ls *.mp4 | head -n 1) + +if [ -z "$VIDEO_FILE" ]; then + echo "No .mp4 files found in the current directory." + exit 1 +fi + +echo "Video File: ${VIDEO_FILE}" + + +# Check if a file was found +if [ -z "$VIDEO_FILE" ]; then + echo "No .mp4 files found in the current directory." + exit 1 +fi + +# Set the artist metadata using ffmpeg +ffmpeg -i "$VIDEO_FILE" -c copy -metadata artist="$ARTIST_NAME" "temp_$VIDEO_FILE" && mv "temp_$VIDEO_FILE" "$VIDEO_FILE" + +echo "Artist metadata set to '$ARTIST_NAME' for file: $VIDEO_FILE"