-
Notifications
You must be signed in to change notification settings - Fork 12
/
util
58 lines (45 loc) · 1.06 KB
/
util
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
#!/usr/bin/env bash
#
# util functions for building the ysap website
#
# Author: Dave Eddy <[email protected]>
# Date: July 11, 2024
# License: MIT
SITE='ysap.sh'
fatal() {
echo '[FATAL]' "$@" >&2
exit 1
}
foreach-video() {
local typ=$1
local callback=$2
local line title num desc pt
local lines links
local base_link="https://$SITE"
for pt in ../"$typ"/pt*/meta.txt; do
unset lines links
mapfile -t lines < "$pt"
title=${lines[0]}
num=${title%%.*}
title=${title#*. }
case "$typ" in
episodes) link=$base_link/v/$num;;
general) link=$base_link/general/v/$num;;
*) fatal "unknown type $typ";;
esac
desc=${lines[1]}
lines=("${lines[@]:2}")
declare -A links
for line in "${lines[@]}"; do
read -r key value <<< "$line"
[[ -n $key && -n $value ]] || continue
links[$key]=$value
done
tiktok=${links[tiktok]}
youtube=${links[youtube]}
instagram=${links[instagram]}
[[ -n $tiktok && -n $youtube && -n $instagram ]] || continue
"$callback" "$num" "$title" "$desc" "$link" \
"$tiktok" "$youtube" "$instagram"
done
}