taggart

Simple golang tagging filesystem webapp
Log | Files | Refs

commit dd3116c2918bc87032aaec53c87df2e9803bd755
parent ef1c11f1d7820e929148e80b83693e6ebcfe36ef
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Sat, 27 Sep 2025 00:54:25 +0100

Allow manually specifying filename and timestamp for backfilled thumbnails

Diffstat:
Mbackfill.sh | 56++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 44 insertions(+), 12 deletions(-)

diff --git a/backfill.sh b/backfill.sh @@ -6,19 +6,51 @@ thumb_dir="$upload_dir/thumbnails" mkdir -p "$thumb_dir" -# Loop through all video files in uploads (not including thumbnails) -find "$upload_dir" -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.webm" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.mkv" \) | while read -r file; do - filename=$(basename "$file") - thumb="$thumb_dir/${filename}.jpg" +target_file="${1:-}" # optional file to override +override_time="${2:-00:00:05}" # default timestamp - if [[ -f "$thumb" ]]; then - echo "Skipping $filename as thumbnail already exists" - continue - fi +generate_thumbnail() { + local file="$1" + local thumb="$2" + local timestamp="$3" - echo "Generating thumbnail for $filename as $thumb" - if ! ffmpeg -y -ss 00:00:05 -i "$file" -vframes 1 -vf scale=400:-1 "$thumb" 2>/dev/null; then - echo "Failed at 5s, retrying from start..." + echo "Generating thumbnail for $(basename "$file") at $timestamp as $thumb" + if ! ffmpeg -y -ss "$timestamp" -i "$file" -vframes 1 -vf scale=400:-1 "$thumb" 2>/dev/null; then + echo "Failed at $timestamp, retrying from start..." ffmpeg -y -i "$file" -vframes 1 -vf scale=400:-1 "$thumb" fi -done +} + +normalize_path() { + local file="$1" + if [[ "$file" == "$upload_dir/"* ]]; then + echo "$file" + else + echo "$upload_dir/$file" + fi +} + +if [[ -n "$target_file" ]]; then + file_path=$(normalize_path "$target_file") + filename=$(basename "$file_path") + thumb="$thumb_dir/${filename}.jpg" + + if [[ ! -f "$file_path" ]]; then + echo "File $file_path not found" + exit 1 + fi + + generate_thumbnail "$file_path" "$thumb" "$override_time" +else + find "$upload_dir" -maxdepth 1 -type f \( -iname "*.mp4" -o -iname "*.webm" -o -iname "*.mov" -o -iname "*.avi" -o -iname "*.mkv" \) | while read -r file; do + filename=$(basename "$file") + thumb="$thumb_dir/${filename}.jpg" + + if [[ -f "$thumb" ]]; then + echo "Skipping $filename as thumbnail already exists" + continue + fi + + generate_thumbnail "$file" "$thumb" "$override_time" + done +fi