-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-assets.sh
executable file
·128 lines (104 loc) · 3.66 KB
/
prepare-assets.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")"
productions="./assets/source/productions/"
images="./assets/source/images/"
legal="./assets/source/legal/"
public_dir="./assets/build/public"
private_dir="./assets/build/private"
mkdir -p "$public_dir"
mkdir -p "$private_dir"
public_dir="$(realpath "$public_dir")"
private_dir="$(realpath "$private_dir")"
imagemagick_args="-strip -interlace JPEG -colorspace RGB -quality 90"
# productions
for production in "$productions"/*; do # "$production = /path/to/B1-damn-it-all-to-hell
production="$(realpath "$production")"
[ ! -d "$production" ] && continue
production_basename="$(basename "$production")" # production_basename = B1-damn-it-all-to-hell
public="false"
source "$production/production.env"
cover="$production/$production_basename-cover.png"
# render="$production/$production_basename-render.png"
cover_128="$public_dir/$production_basename-cover-128.jpeg"
cover_256="$public_dir/$production_basename-cover-256.jpeg"
cover_512="$public_dir/$production_basename-cover-512.jpeg"
cover_1024="$public_dir/$production_basename-cover-1024.jpeg"
# render_768="$public_dir/$production_basename-render-768.jpeg"
[ -f "$cover_128" ] || convert "$cover" $imagemagick_args -resize 128x "$cover_128"
[ -f "$cover_256" ] || convert "$cover" $imagemagick_args -resize 256x "$cover_256"
[ -f "$cover_512" ] || convert "$cover" $imagemagick_args -resize 512x "$cover_512"
[ -f "$cover_1024" ] || convert "$cover" $imagemagick_args -resize 1024x "$cover_1024"
# [ -f "$render_768" ] || convert "$render" $imagemagick_args -resize x768 "$render_768"
if [ "$public" = 'true' ]; then
zip="$public_dir/$production_basename.zip"
else
zip="$private_dir/$production_basename.zip"
fi
if [ ! -f "$zip" ]; then
zip_temp="$(mktemp -d)"
track_count="$(ls "$production/tracks/" | wc -l)"
fi
for track in "$production/tracks"/*; do
track="$(realpath "$track")"
source "$track/track.env"
track_basename="$(basename "$track")" # track_basename = B1-1-damn-it-all-to-hell
master="$track/$track_basename-master.wav"
aac="$public_dir/$track_basename-master.aac"
ogg="$public_dir/$track_basename-master.ogg"
[ -f "$aac" ] || ffmpeg -i "$master" -b:a 192k \
-metadata title="$title" \
-metadata album="$album" \
-metadata album_artist="$album_artist" \
-metadata TBPM="$bpm" \
"$aac"
[ -f "$ogg" ] || ffmpeg -i "$master" -b:a 192k \
-metadata title="$title" \
-metadata album="$album" \
-metadata album_artist="$album_artist" \
-metadata TBPM="$bpm" \
"$ogg"
if [ -d "$zip_temp" ]; then
if [ "$track_count" -eq 1 ]; then
# only one track
master_dir="$zip_temp/$album/"
stems_dir="$zip_temp/$album/stems"
else
# more than one track
master_dir="$zip_temp/$album/compositions/"
stems_dir="$zip_temp/$album/stems/$title"
fi
mkdir -p "$master_dir"
ffmpeg -i "$master" \
-metadata title="$title" \
-metadata album="$album" \
-metadata album_artist="$album_artist" \
-metadata TBPM="$bpm" \
"$master_dir/$title.wav"
mkdir -p "$(dirname "$stems_dir")"
ln -s "$track/stems" "$stems_dir"
fi
done
if [ -d "$zip_temp" ]; then
(cd "$zip_temp" && zip -r "$zip" .)
rm -rf "$zip_temp"
fi
done
# images
prepare_image () {
image=$1
height=$2
echo $image
basename="$(basename "$image")"
name="${basename%.*}"
out="$public_dir/$name.jpeg"
[ -f "$out" ] || convert "$image" -resize x$height $imagemagick_args "$out"
}
prepare_image "$images/hero-mihailo-wide.png" 1024
# prepare_image "$images/hero-mihailo-tall.png" 1024
# legal
for docx in "$legal"/*.docx; do
basename="$(basename "$docx")"
name="${basename%.*}"
pandoc "$docx" -o "$public_dir/$name.html"
done