changes - hope they work

This commit is contained in:
2026-03-14 11:13:56 +01:00
parent 867124d2fd
commit 335aa54621
5 changed files with 171 additions and 46 deletions

View File

@ -12,7 +12,7 @@ set -euo pipefail
# ---- Defaults ----
DRY_RUN=0
RECURSIVE=0
PREFIX="PINK_"
PREFIX="[WUNF_*]"
DURATION="1.0"
FPS="6"
HUE_MIN="285"
@ -48,6 +48,13 @@ while [[ $# -gt 0 ]]; do
esac
done
# ---- Derived rename prefix ----
RENAME_PREFIX="$PREFIX"
# Om PREFIX har formen [TEXT_*] (t.ex. [WUNF_*]) så gör vi rename-prefix = [TEXT]_
if [[ "$PREFIX" =~ ^\[([^][]+)_\*\]$ ]]; then
RENAME_PREFIX="[${BASH_REMATCH[1]}]_"
fi
# ---- Helpers ----
print_result() { # $1=status $2=file $3=detail
printf "%-10s %s%s\n" "$1" "$2" "${3:+ ($3)}"
@ -114,6 +121,23 @@ detect_pink() { # $1=file -> echoes "total pink ratio"
is_mp4() { case "$1" in *.mp4|*.MP4) return 0;; *) return 1;; esac; }
# Prefix-match med optional * = 13 siffror
is_prefixed() { # $1=basename $2=prefix
local base="$1" prefix="$2"
# Special handling for patterns like [TEXT_*]
if [[ "$prefix" =~ ^\[([^][]+)_\*\]$ ]]; then
local tag="${BASH_REMATCH[1]}"
# Already-prefixed means: [TAG]_... or [TAG_###]_... at the start
local re="^\[$tag(_[0-9]{1,3})?]_"
[[ "$base" =~ $re ]]
else
# Fallback: simple "starts with prefix"
[[ "$base" == "$prefix"* ]]
fi
}
# ---- File list ----
if [[ $RECURSIVE -eq 1 ]]; then
mapfile -t FILES < <(find "$DIR" -type f \( -iname '*.mp4' \))
@ -132,7 +156,8 @@ for f in "${FILES[@]}"; do
is_mp4 "$f" || { print_result "SKIPPED" "$f" "not mp4"; continue; }
base=$(basename -- "$f")
if [[ "$base" == "$PREFIX"* ]]; then
# Matchning använder PREFIX (med * → 13 siffror)
if is_prefixed "$base" "$PREFIX"; then
print_result "SKIPPED" "$f" "already prefixed"
continue
fi
@ -144,7 +169,8 @@ for f in "${FILES[@]}"; do
fi
awk -v r="$ratio" -v thr="$MIN_RATIO" 'BEGIN{exit !(r>=thr)}' && {
safe_rename "$f" "$PREFIX"
# Omdöpning använder RENAME_PREFIX (t.ex. [WUNF]_)
safe_rename "$f" "$RENAME_PREFIX"
continue
}