blob: 8ee6d5107a6e4a1819f71fd0012e6412a92179ca (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <directory>"
exit 1
fi
input_dir="$1"
find "$input_dir" -type d | while read -r dir; do
image=""
for ext in jpg JPG jpeg JPEG png PNG; do
found=$(find "$dir" -maxdepth 1 -type f -name "*.${ext}" | head -n 1)
if [[ -n "${found:-}" ]]; then
image="$found"
break
fi
done
[[ -z "$image" ]] && continue
echo "Processing folder: $dir"
echo "Using image: $image"
ext_lower="${image##*.}"
ext_lower="${ext_lower,,}"
if [[ "$ext_lower" == "png" ]]; then
mimetype="image/png"
suffix=".png"
else
mimetype="image/jpeg"
suffix=".jpg"
fi
temp_cover="$(mktemp --suffix=${suffix})"
ffmpeg -y -i "$image" \
-vf "scale=500:500:force_original_aspect_ratio=decrease,pad=500:500:(ow-iw)/2:(oh-ih)/2" \
"$temp_cover" >/dev/null 2>&1
find "$dir" -maxdepth 1 -type f -iname "*.flac" | while read -r flac; do
echo "Tagging: $flac"
metaflac --remove --block-type=PICTURE "$flac"
metaflac --import-picture-from="3|${mimetype}|||$temp_cover" "$flac"
done
rm -f "$temp_cover"
done
|