#!/usr/bin/bash
#License: GPL-3.0-or-later
url=https://112122.xyz
f=menu
[[ $FFCODEC ]]||FFCODEC=(libvpx-vp9 -deadline best -crf 63)
fs=(-movflags faststart -map 0:v)
vf=;[[ $NOPAD ]]||vf=',pad=h=ceil(ih*1.10/2)*2:w=ceil(round(oh*16/9)/2)*2:x=(ow-iw)*0.4:y=-1'
old(){
  t=$(date -u +%FT%RZ)
  for i in "${@:2}";do
    mv -v "$i" "$1/$t${i##*/}"
  done
}
track(){
  for i in "$@";do ffprobe -v warning -show_entries format:stream -of json "$i";done|jq -r '.format.filename as $f|([.format,(.streams|map(select(has("tags")))[0]//{})|.tags]|if .[0] then ["",.[0]] else if .[1] then [":s",.[1]] else ["",{}] end end) as $t|def tag(n;$d):reduce n as $i([$f];. as $a|$i|[.,ascii_upcase]|[.[0],.[1][:1]+.[0][1:],.[1]]|$t[1][.[0]]//$t[1][.[1]]//$t[1][.[2]]|if . and length>0 and (if $d then . else [.==($a|..)]|any|not end) then $a+[.] else $a+[null] end);.format.duration as $d|tag("artist","album_artist","title","album","date";true)|if .[2] then .[1:] else .[2]=(.[0]|split("/")[-1])|.[1:] end|if .[0] then [.[0]]+.[2:] else .[1:] end|$d+" "+(.[:-1]|map(select(.))|join(" - "))+(.[-1]|if . then " (\(.))" else "" end)'
}
check(){
  if [[ -s "$1" ]];then
    printf '%q already exists. Overwrite? [y/N]\n' "$1"
    read -sn1
    [[ $REPLY =~ ^[Yy]$ ]]||exit 1
  fi
}
if [[ $# = 1 && "$1" =~ \.css$ ]];then
  check "$1"
  b="$(basename "$1" .css)"
  curl https://fonts.bunny.net/css\?family=$b:100,200,300,400,500,600,700,800,900|
    sed -r '/^$|^\/|font-style:\s*normal/d;s/^\s*src:\s*url\(([^()]+)\).*/\/\1/;s/[ \t]+//g'|
    while read l;do
      if [[ "$l" =~ ^/(.*/"$b"(-latin|(-[^-]+))(-e(x)t)?-([1-9]+)0*-(n|([^-.]))[^-.]+(\..*)) ]]
      then m=("${BASH_REMATCH[@]}")
        l=$b${m[3]}${m[6]}${m[8]}${m[5]}${m[9]}
        printf 'src:url(%s/%s);\n' $url $l|tee /dev/stderr
        curl -o "$(dirname "$1")"/$l "${m[1]}"
      else echo $l;fi
    done > "$1"
elif [[ $# -ge 3 && "$1" =~ \.(woff2?|ttf|otf)$ ]];then
  check "$1"
  fontforge -lang=ff -c "Open(\$2);$(printf 'MergeFonts($%d);' $(seq 3 $#))Generate(\$1);Close()" "$@"
elif [[ $# -ge 2 && "$1" = track ]];then track "${@:2}"
elif [[ $# -ge 5 && "$1" =~ ^([0-9]+k|0)$ ]];then
  m=(-map_metadata -1 -metadata "comment=$(track "${@:4}"|jq -Rrn 'reduce inputs as $i([0,[]];. as $s|$i|split(" ")|[$s[0]+(.[0]|tonumber),$s[1]+[.[1:]|(reduce (60,60) as $i([$s[0]|round];[.[0]/$i]+(.[0]|=.%$i))|map(numbers|=(fabs|trunc|tostring|(2-length)*"0"+.))|join(":"))+" "+join(" ")]])|.[1][]'|tee /dev/stderr|tee "$2")")||exit 1
  if [[ $1 = 0 ]];then
    ffmpeg -f concat -safe 0 -i <(realpath "${@:4}"|jq -Rr '@sh "file \(.)"') -c copy "${m[@]}" "$3"
  else
    realpath "${@:4}"|jq -Rrn --arg b $1 --arg o "$(realpath "$3")" '[inputs]|["ffmpeg",(.[]|"-i",.),"-filter_complex","[a]concat=n=\(length):v=0:a=1","-b:a",$b,$ARGS.positional[],$o]|@sh' --args -- "${m[@]}"|bash
  fi
  [[ -s "$3" ]]||exit 1
elif [[ $# = 2 && -s "$1" && "$1" =~ \.(png|jpe?g|webp|avif)$ ]];then
  ff=(ffmpeg -hide_banner -v error -framerate 1 -i "$1" -r 1 -vf "color=c=black:size=$(ffprobe -v 16 -show_entries stream=width,height -of default=noprint_wrappers=1:nokey=1 "$1"|jq -Rrn '[inputs]|join("x")'),overlay$vf,loop=-1:1" -c:v "${FFCODEC[@]}" -b:v 0 -g 300 -threads 5 -pix_fmt yuv420p "${fs[@]}" -t 300 -y)
  if [[ "$FFCODEC" =~ ^libvpx-vp9 ]];then
    "${ff[@]}" -pass 1 -f null /dev/null&&"${ff[@]}" -pass 2 "$2"
  else "${ff[@]}" "$2";fi
  [[ -s "$2" ]]||exit 1
elif [[ $# = 3 && -s "$1" && "$1" =~ \.(webm|mkv)$ && "$2" =~ \.(webm|mkv)$ && -s "$3" && "$3" =~ \.(opus|ogg|webm|mk[va])$ ]];then
  ffmpeg -hide_banner -v error -f concat -safe 0 -i <(realpath "$1"|jq -Rr '@sh "file \(.)"|range(0;1000) as $i|.') -i "$3" -c:a copy "${fs[@]}" -c:v copy -map 1:a -shortest -y "$2"&&[[ -s "$2" ]]||exit
  [[ $NOCACHE ]]&&exit # cache
  b h n c "${2##*/}" # cache
elif [[ $# = 3 && "$3" = tmp && -d "$1" && -d "$2" ]];then
  so=_tmp
  #export L10NS=1
  #export MENUSO=1
  menu_tmp(){
        #L10N=ru "$0" "$1" "$2" menu_ru"$so"_full 2 100 1 &&
        #L10N=ru "$0" "$1" "$2" menu_ru"$so"_full_compact 2 100 1 1 4 2 0 0 &&
        #L10N=ru FONT=tiny5-cyrillic4l.woff2 "$0" "$1" "$2" menu_ru"$so"_full_tiny 0 94 1 1 4 2 &&
        #L10N=ru FONT=tiny5-cyrillic4l.woff2 "$0" "$1" "$2" menu_ru"$so"_full_compact_tiny 0 108 1 1 4 2 0 0 &&
        #L10N=ru FONT=press-start-2p-cyrillic4l.woff2 "$0" "$1" "$2" menu_ru"$so"_full_ps2p 0 65 1 &&
        #L10N=ru FONT=press-start-2p-cyrillic4l.woff2 "$0" "$1" "$2" menu_ru"$so"_full_compact_ps2p 0 75 1 1 3 2 0 0 &&
    #"$0" "$1" "$2" menu"$so" &&
    :
  }
  menu_tmp "$1" "$2" &&
  :
elif [[ $# = 3 && -d "$1" && -d "$2" && -f "$3" && "$3" =~ \.(opus|ogg|webm|mk[va])$ ]];then
  so=
  if [[ "$MENUSO" = 1 ]];then
    so=_chrono
  else
    MENUSO=1 "$0" "$1" "$2" "$3" &
  fi
  menu_en(){
    "$0" "$1" "$2" menu"$so" 2 100 0 1 4 3 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_cyber 2 133 0 1 4 3 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_tomorrow 0 100 0 1 4 3 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_sans 2 100 0 1 4 3 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_tiny 0 130 0 1 4 3 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_ps2p 0 90 &&
      "$0" "$1" "$2" menu"$so"_compact 2 110 0 1 4 3 0 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_compact_cyber 2 140 0 1 4 4 0 0 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_compact_tiny 0 140 0 1 4 3 0 0 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_compact_ps2p 0 80 0 1 4 2 0 0 &&

      "$0" "$1" "$2" menu"$so"_full 2 100 1 1 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_cyber 2 100 1 1 4 2 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_full_tiny 0 105 1 1 4 2 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_full_ps2p 0 70 1 1 3 1.5 &&
        FONT=pixelify-sans4.woff2 "$0" "$1" "$2" menu"$so"_full_pixel 0 115 1 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_culpa 0 140 1 1 4 3 0 1 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_culpa_bold 1 140 1 1 4 3 0 1 &&
      "$0" "$1" "$2" menu"$so"_full_compact 2 92 1 1 4 2 0 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_compact_cyber 2 120 1 1 4 2 0 0 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_full_compact_tiny 0 120 1 1 4 2 0 0 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_full_compact_ps2p 0 80 1 1 3 2 0 0 &&
        FONT=pixelify-sans4.woff2 "$0" "$1" "$2" menu"$so"_full_compact_pixel 0 105 1 1 4 1.5 0 0 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_cyber 2 210 1 1 2 3 &&
    "$0" "$1" "$2" menu"$so"_portrait 2 140 0 1 2 3 0 1 1500 3000 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_portrait_cyber 2 180 0 1 2 3 0 1 1500 3000 &&

      "$0" "$1" "$2" menu"$so"_full_portrait_compact 2 135 1 1 2 2 0 0 1500 3000 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_portrait_compact_cyber 2 175 1 1 2 2 0 0 1500 3000 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_portrait_compact_culpa 0 150 1 1 3 3 0 0 1500 3000 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_portrait_compact_culpa_bold 1 150 1 1 3 3 0 0 1500 3000 &&
    "$0" "$1" "$2" menu"$so"_customer 2 65 0 1 10 7 2 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_cyber 2 85 0 1 10 7 2 0 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_customer_tomorrow 0 75 0 1 10 7 2 0 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_customer_sans 2 75 0 1 11 7 2 0 &&

      "$0" "$1" "$2" menu"$so"_full_customer 2 60 1 1 9 5 2 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_cyber 2 78 1 1 9 5 2 0 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_full_customer_tomorrow 0 60 1 1 9 6 2 0 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_full_customer_sans 2 57 1 1 10 7 2 0 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_customer_cyber 2 160 1 1 4 5 2 0 &&
    "$0" "$1" "$2" menu"$so"_customer_text 2 100 0 1 4 3 4 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_text_cyber 2 127 0 1 4 3 4 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_customer_text_tiny 0 130 0 1 4 2 4 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_customer_text_ps2p 0 90 0 1 3 2 4 &&
      "$0" "$1" "$2" menu"$so"_customer_text_compact 2 100 0 1 6 3 4 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_text_compact_cyber 2 150 0 1 5 3 4 0 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_customer_text_compact_tiny 0 160 0 1 5 2 4 0 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_customer_text_compact_ps2p 0 100 0 1 4 2 4 0 &&

      "$0" "$1" "$2" menu"$so"_full_customer_text 2 100 1 1 3 2 4 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_cyber 2 100 1 1 4 3 4 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_full_customer_text_tiny 0 105 1 1 4 2 4 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_full_customer_text_ps2p 0 70 1 1 3 1.5 4 &&
        FONT=pixelify-sans4.woff2 "$0" "$1" "$2" menu"$so"_full_customer_text_pixel 0 115 1 1 3 2 4 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_customer_text_culpa 0 140 1 1 4 3 4 1 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_customer_text_culpa_bold 1 140 1 1 4 3 4 1 &&
      "$0" "$1" "$2" menu"$so"_full_customer_text_compact 2 110 1 1 4 2 4 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_compact_cyber 2 145 1 1 4 2 4 0 &&
        FONT=tiny54.woff2 "$0" "$1" "$2" menu"$so"_full_customer_text_compact_tiny 0 140 1 1 4 3 4 0 &&
        FONT=press-start-2p4.woff2 "$0" "$1" "$2" menu"$so"_full_customer_text_compact_ps2p 0 90 1 1 3 2 4 0 &&
        FONT=pixelify-sans4.woff2 "$0" "$1" "$2" menu"$so"_full_customer_text_compact_pixel 0 120 1 1 4 2 4 0 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_customer_text_compact_culpa 0 160 1 1 5 3 4 0 &&
        FONT=mea-culpa4.woff2 FTLC=1 "$0" "$1" "$2" menu"$so"_full_customer_text_compact_culpa_bold 1 160 1 1 5 3 4 0 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_customer_text_cyber 2 210 1 1 2 3 4 &&
    "$0" "$1" "$2" menu"$so"_customer_visual 2 50 0 1 18 10000 1 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_visual_cyber 2 66 0 1 18 10000 1 0 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_customer_visual_tomorrow 0 58 0 1 18 10000 1 0 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_customer_visual_sans 2 60 0 1 18 10000 1 0 &&

      "$0" "$1" "$2" menu"$so"_full_customer_visual 2 46 1 1 14 10000 1 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_visual_cyber 2 60 1 1 14 10000 1 0 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_full_customer_visual_tomorrow 0 50 1 1 14 10000 1 0 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_full_customer_visual_sans 2 46 1 1 17 10000 1 0 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_customer_visual_cyber 2 120 1 1 8 10000 1 0 &&


    "$0" "$1" "$2" menu"$so"_loco 2 100 0 0 4 3 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_cyber_loco 2 133 0 0 4 3 &&
      "$0" "$1" "$2" menu"$so"_compact_loco 2 110 0 0 4 3 0 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_compact_cyber_loco 2 140 0 0 4 4 0 0 &&

      "$0" "$1" "$2" menu"$so"_full_loco 2 100 1 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_cyber_loco 2 100 1 0 4 2 &&
      "$0" "$1" "$2" menu"$so"_full_compact_loco 2 92 1 0 4 2 0 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_compact_cyber_loco 2 120 1 0 4 2 0 0 &&
    "$0" "$1" "$2" menu"$so"_portrait_loco 2 140 0 0 2 3 0 1 1500 3000 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_portrait_cyber_loco 2 180 0 0 2 3 0 1 1500 3000 &&

      "$0" "$1" "$2" menu"$so"_full_portrait_compact_loco 2 135 1 0 2 2 0 0 1500 3000 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_portrait_compact_cyber_loco 2 175 1 0 2 2 0 0 1500 3000 &&
    FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_cyber_loco 2 78 1 0 9 5 2 0 &&
    "$0" "$1" "$2" menu"$so"_customer_text_loco 2 100 0 0 4 3 4 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_text_cyber_loco 2 127 0 0 4 3 4 &&
      "$0" "$1" "$2" menu"$so"_customer_text_compact_loco 2 100 0 0 6 3 4 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_text_compact_cyber_loco 2 150 0 0 5 3 4 0 &&

      "$0" "$1" "$2" menu"$so"_full_customer_text_loco 2 100 1 0 3 2 4 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_cyber_loco 2 100 1 0 4 3 4 &&
      "$0" "$1" "$2" menu"$so"_full_customer_text_compact_loco 2 110 1 0 4 2 4 0 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_compact_cyber_loco 2 145 1 0 4 2 4 0 &&


    "$0" "$1" "$2" menu"$so"_print 2 90 0 1 4 3 0 1 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_print_cyber 2 100 0 1 5 3 0 1 1920 1080 &&
      "$0" "$1" "$2" menu"$so"_print_compact 2 85 0 1 5 3 0 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_print_compact_cyber 2 110 0 1 5 3 0 0 1920 1080 &&

      "$0" "$1" "$2" menu"$so"_full_print 2 75 1 1 4 2 0 1 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_print_cyber 2 95 1 1 4 2 0 1 1920 1080 &&
      "$0" "$1" "$2" menu"$so"_full_print_compact 2 85 1 1 4 2 0 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_print_compact_cyber 2 110 1 1 4 2 0 0 1920 1080 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_print_cyber 2 190 1 1 2 3 0 1 1920 1080 &&
    "$0" "$1" "$2" menu"$so"_customer_print 2 55 0 1 11 7 2 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_print_cyber 2 70 0 1 11 6 2 0 1920 1080 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_customer_print_tomorrow 0 60 0 1 11 8 2 0 1920 1080 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_customer_print_sans 2 58 0 1 12 8 2 0 1920 1080 &&

      "$0" "$1" "$2" menu"$so"_full_customer_print 2 50 1 1 10 5 2 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_print_cyber 2 65 1 1 10 5 2 0 1920 1080 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_full_customer_print_tomorrow 0 53 1 1 10 5 2 0 1920 1080 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_full_customer_print_sans 2 50 1 1 11 6 2 0 1920 1080 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_customer_print_cyber 2 135 1 1 5 6.5 2 0 1920 1080 &&
    "$0" "$1" "$2" menu"$so"_customer_text_print 2 90 0 1 4 3 4 1 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_text_print_cyber 2 98 0 1 5 3 4 1 1920 1080 &&
      "$0" "$1" "$2" menu"$so"_customer_text_print_compact 2 115 0 1 5 2 4 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_text_print_compact_cyber 2 125 0 1 6 2 4 0 1920 1080 &&

      "$0" "$1" "$2" menu"$so"_full_customer_text_print 2 74 1 1 4 2 4 1 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_print_cyber 2 95 1 1 4 2 4 1 1920 1080 &&
      "$0" "$1" "$2" menu"$so"_full_customer_text_print_compact 2 85 1 1 5 2 4 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_print_compact_cyber 2 110 1 1 5 2 4 0 1920 1080 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_customer_text_print_compact_cyber 2 200 1 1 3 2 4 0 1920 1080 &&
    "$0" "$1" "$2" menu"$so"_customer_visual_print 2 40 0 1 20 10000 1 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_visual_print_cyber 2 56 0 1 19 10000 1 0 1920 1080 &&
        FONT=tomorrow6.woff2 "$0" "$1" "$2" menu"$so"_customer_visual_print_tomorrow 0 46 0 1 20 10000 1 0 1920 1080 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_customer_visual_print_sans 2 45 0 1 24 10000 1 0 1920 1080 &&

      "$0" "$1" "$2" menu"$so"_full_customer_visual_print 2 34 1 1 18 10000 1 0 1920 1080 &&
        FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_visual_print_cyber 2 46 1 1 17 10000 1 0 1920 1080 &&
        FONT=tomorrow7.woff2 "$0" "$1" "$2" menu"$so"_full_customer_visual_print_tomorrow 0 40 1 1 16 10000 1 0 1920 1080 &&
        FONT=sans "$0" "$1" "$2" menu"$so"_full_customer_visual_print_sans 2 40 1 1 18 10000 1 0 1920 1080 &&
    MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic"$so"_full_customer_visual_print_cyber 2 100 1 1 9 10000 1 0 1920 1080 &&


    FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_print_cyber_loco 2 100 0 0 5 3 0 1 1920 1080 &&
      FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_customer_print_cyber_loco 2 70 0 0 11 6 2 0 1920 1080 &&
      FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu"$so"_full_customer_text_print_cyber_loco 2 95 1 0 4 2 4 1 1920 1080
  }
  menu_jp(){
    if [[ "$L10NS" = 1 ]];then
      so=
    elif [[ ! "$so" ]];then
      so=_en
    fi &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full 2 90 1 1 4 2 &&
      L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_compact 2 100 1 1 4 4 0 0 &&
    L10N=jp MENUSRC=GV "$0" "$1" "$2" menu_jp_classic"$so"_full_compact 2 190 1 1 2 1 0 0 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_portrait_compact 2 150 1 1 2 3 0 0 1500 3000 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer 2 65 1 1 10 5 2 0 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_text 2 90 1 1 4 2 4 &&
      L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_text_compact 2 135 1 1 4 2 4 0 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_visual 2 50 1 1 16 10000 1 0 &&

    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_loco 2 120 1 0 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_portrait_compact_loco 2 150 1 0 2 3 0 0 1500 3000 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_loco 2 65 1 0 10 5 2 0 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_text_loco 2 120 1 0 3 2 4 &&

    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_print 2 85 1 1 4 2 0 1 1920 1080 &&
      L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_print_compact 1 100 1 1 4 2 0 0 1920 1080 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_print 1 55 1 1 12 4 2 0 1920 1080 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_text_print 2 85 1 1 4 2 4 1 1920 1080 &&
      L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_text_print_compact 2 100 1 1 5 2 4 0 1920 1080 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_visual_print 1 43.5 1 1 18 10000 1 0 1920 1080 &&

    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_print_compact_loco 1 100 1 0 4 2 0 0 1920 1080 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_print_loco 1 55 1 0 12 4 2 0 1920 1080 &&
    L10N=jp "$0" "$1" "$2" menu_jp"$so"_full_customer_text_print_loco 2 85 1 0 4 2 4 1 1920 1080
  }
  menu_en "$1" "$2" &&
  menu_jp "$1" "$2" &&
  if [[ ! "$MENUSO" ]];then
    L10NS=1 menu_jp "$1" "$2" &&
    "$0" "$1" "$2" menu_sticker 1 70 0 1 3 2 0 1 1024 1024 &&
        "$0" "$1" "$2" menu_full_sticker_compact 1 60 1 1 3 2 0 0 1024 1024 &&
      MENUSO=1 MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic_chrono_full_sticker_compact_cyber 1 125 1 1 2 2 0 0 1024 1024 &&
      MENUSO=1 MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic_chrono_full_customer_sticker_cyber 1 100 1 1 4 4 2 0 1024 1024 &&
      "$0" "$1" "$2" menu_customer_text_sticker_compact 1 80 0 1 4 2 4 0 1024 1024 &&
        "$0" "$1" "$2" menu_full_customer_text_sticker_compact 1 75 1 1 3 2 4 0 1024 1024 &&
      MENUSO=1 MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic_chrono_full_customer_text_sticker_cyber 1 110 1 1 2 2 4 1 1024 1024 &&
        MENUSO=1 MENUSRC=GV FONT=CyberpunkWaifus.ttf "$0" "$1" "$2" menu_classic_chrono_full_customer_text_sticker_compact_cyber 1 160 1 1 2 2 4 0 1024 1024 &&
    "$0" "$1" "$2" menu_video 2 72 1 1 4 2 0 0 1600 981 &&
      "$0" "$2"/menu_video.{webp,v.webm} &&
      "$0" "$2"/menu{_video.v,}.webm "$3" &&
    FONT=tomorrow6.woff2 "$0" "$1" "$2" menu_customer_video 0 44 0 1 18 10000 1 0 1600 981 &&
      "$0" "$2"/menu_customer_video.{webp,v.webm} &&
      "$0" "$2"/menu_customer{_video.v,}.webm "$3" &&
    L10NS=1 L10N=jp "$0" "$1" "$2" menu_jp_video 2 82 1 1 4 2 0 0 1600 981 &&
      "$0" "$2"/menu_jp_video.{webp,v.webm} &&
      "$0" "$2"/menu_jp{_video.v,}.webm "$3" &&
    L10NS=1 L10N=jp "$0" "$1" "$2" menu_jp_customer_video 2 40 1 1 16 10000 1 0 1600 981 &&
      "$0" "$2"/menu_jp_customer_video.{webp,v.webm} &&
      "$0" "$2"/menu_jp_customer{_video.v,}.webm "$3"
  fi
elif [[ $# -ge 2 && $# -le 3 && -d "$1" && -d "$2" ]];then
  o="$(realpath "$1")"
  d="$(realpath "$2")"
  c="$(mktemp)"
  #j="$(mktemp)"
  cd "$d"
  #curl --skip-existing -o OCR-B.woff https://web.archive.org/web/20190328152441/https://wehtt.am/ocr-b/fonts/ocr-b/OCR-B-regular-web.woff
  curl -Z --skip-existing --remote-name-all $url'/{OCR-B.woff,CyberpunkWaifus.ttf,noto-jp.otf}' $url'/tomorrow[1-9].woff2' $url'/{tiny54,tiny5-cyrillic4l,press-start-2p4,press-start-2p-cyrillic4l,pixelify-sans4,mea-culpa4}.woff2'
  curl -L 'https://docs.google.com/spreadsheets/d/1EbuFcaFwFi206QT4pRqk2sTQ9-VYA9pl/export?gid=600503244&format=csv'|grep -v '^,,,'|grep -FA999 'Drink Machine Name' > "$c"
  if [[ $? != 0 || ! -s "$c" || "$(cat "$c"|file --mime-type -|cut -f2 -d\ )" != text/csv ]]||
      { diff -s "$f.o.csv" "$c"&&[[ $3 != 1 ]] };then
    rm "$c"
    exit 1
  fi
  cat "$c"|wc
  #curl -L 'https://docs.google.com/spreadsheets/d/1EbuFcaFwFi206QT4pRqk2sTQ9-VYA9pl/export?format=zip&id=1EbuFcaFwFi206QT4pRqk2sTQ9-VYA9pl'|bsdtar Ox --exclude '*old*' '*Customer*'|pup -p --charset UTF-8 table json{}|jq 'def i($i;b;c):if $i then $i|b else c end;.[0].children[1].children|. as $a|reduce range(0;length) as $r({s:"menu"};$a[$r].children as $a|reduce range(2;$a|length) as $c(.;. as $m|$a[$c] as $n|i($n.text|. as $i|i(type=="string" and test("\\D");$i;null);. as $i|$m|.[.s]|=.+[{r:($r-1),c:($c-2),s:$m.s,n:$i}];i($n.children[0].children[0].src?;. as $i|$m|.[.s]|=.+[{r:$r,c:($c-2),s:$m.s,i:$i}];i($n.children[0].text?;. as $i|i(length>0 and length<50;$m|.s=$i;$m);.)))))|del(.s)|.[]|=(group_by(.r)|map(group_by(.c)|map(add)[]))|del(."Owner\u0027s Secret")|add' > "$j"
  #if [[ $? != 0 || ! -s "$j" || $(wc -c<"$j") -lt 99 ]];then
    #rm "$c" "$j"
    #exit 2
  #fi
  old "$o" $f.{o.csv,csv,json,txt}
  mv -v "$c" "$f.o.csv"
  sqlite3 '' ".import --csv '$f.o.csv' _" '.mode csv' '.headers on' 'UPDATE _ SET "Drink Name"=TRIM("Drink Name"),"Drink Machine Name"=TRIM("Drink Machine Name"),"Japanese Name"=TRIM("Japanese Name"),"Russian Name"=TRIM("Russian Name")' "SELECT * FROM _ WHERE \"Drink Name\"!='' ORDER BY \"Drink Name\""|tr -d '\015"' > "$f.csv"
  cat "$f.csv"|sqlite3 '' '.import --csv /dev/stdin _' '.mode json' "UPDATE _ SET Adelhyde='X' WHERE Adelhyde='10'" "UPDATE _ SET \"Bronson Extract\"='X' WHERE \"Bronson Extract\"='10'" "UPDATE _ SET \"Powdered Delta\"='X' WHERE \"Powdered Delta\"='10'" "UPDATE _ SET Flanergide='X' WHERE Flanergide='10'" "CREATE TABLE o AS SELECT '' n,'' m,'' j,'' p,'A' i1,'B' i2,'D' i3,'F' i4,'' k,'K' i5,'I' i,'A' a,'B' b,'C' c,'D' d,'X' x,'O' o,'00000000' l,'-1' r,'-1' u" "INSERT INTO o SELECT \"Drink Name\" n,\"Drink Machine Name\" m,\"Japanese Name\" j,\"Russian Name\" p,Adelhyde i1,\"Bronson Extract\" i2,\"Powdered Delta\" i3,Flanergide i4,CASE \"Optional Karmotrine?\" WHEN 'Yes' THEN '.' END k,CASE \"Minimum Karmotrine\" WHEN '0' THEN \"Maximum Karmotrine\" ELSE \"Minimum Karmotrine\" END i5,CASE \"Iced?\" WHEN 'Yes' THEN 'I' WHEN 'Opt.' THEN 'i' END i,CASE \"Aged?\" WHEN 'Yes' THEN 'A' WHEN 'Opt.' THEN 'a' END a,CASE \"Blended?\" WHEN 'Yes' THEN 'B' WHEN 'Opt.' THEN 'b' END b,CASE \"Cure?\" WHEN 'Yes' THEN 'C' END c,CASE \"Can be doubled?\" WHEN 'Yes' THEN '2' END d,CASE \"Custom SFX?\" WHEN 'Yes' THEN 'X' END x,SUBSTR(Source,1,1) o,Color l,Row r,Column u FROM _" 'SELECT * FROM o ORDER BY n' > "$f.json"
  cat "$f.json"|jq -r '"By AutumnFiametta & 17953648\nKey: Ice Age Blend Cure Double SFX Origin",((map(.m|length)|max) as $l|.[]|. as $n|"\(.m|if .=="" then "Name" end|.+" "*($l-length)) \(.i1) \(.i2) \(.i3) \(.i4)\(.k+" "|.[:1])\(.i5|" "*(2-length)+.) \(.i//" ")\(.a//" ")\(.b//" ") \(.c//" ")\(.d//" ")\(.x//" ")\(.o)")' > "$f.txt"
  #cat "$j"|jq -r --arg d "$d" '@sh "curl -Z --skip-existing --output-dir \($d) \(map("-o",.n+".png",.i))"'|bash
  curl -Z --skip-existing --output-dir "$d" -O $url'/{ice,blend}.webp'
  cat "$f.json"|jq -r --arg d "$d" '@sh "curl -Z --skip-existing --output-dir \($d) \(map(.n|select(length>0)|.+".webp"|"-o",.,@uri "'$url'/\(.)"))"'|bash
  #rm "$j"
  chmod 644 "$f".{o.csv,csv,json,txt}
  [[ -s "$f.o.csv" && -s "$f.csv" && -s "$f.json" && -s "$f.txt" ]]||exit 1
  [[ $NOCACHE ]]&&exit # cache
  b h n c '' "${f##*/}".{o.csv,csv,json,txt} # cache
elif [[ $# -ge 5 && $# -le 13 && -d "$1" && -d "$2" ]];then
  o="$(realpath "$1")"
  d="$(realpath "$2")"
  printf '[%s] ' "$o" "$d" "${@:3}";echo
  cd "$d"
  old "$o" "$3".{ffmpeg,ffmpeg1,webp}
  { printf 'cd "%s"\n' "$d";cat "$f.json"|jq -r --arg i "$3" --arg b $4 --argjson f $5 --arg l "$6" --arg d "" --arg g "$7" --arg c "$8" --arg s "$9" --arg p "${11}" --arg u "${10}" --arg W "${12}" --arg H "${13}" --arg T "$FONT" --arg j "$L10N" --arg js "$L10NS" --arg ms "$MENUSRC" --arg mo "$MENUSO" --arg lc "$FTLC" 'def i($a;b;c):if $a then b else c end;def t:.;def esc:gsub("(?<x>[\\[\\],])";"\\\(.x)");def j:(utf8bytelength-length|0)*"?";i($T!="";"";":fontfile=noto-jp.otf") as $jp|i($T=="";"OCR-B.woff";$T) as $T|def n($n):i(type=="number";.;i(type=="string";trim|tonumber? //$n;$n));($u|n(0)) as $u|def color:i($g=="0";"";"\(.)" as $n|{"10":"88ff88","12":"ff9999"}|i($u==4;{"2":.["10"],"3":.["12"]};.)|i(has($n);.[$n]|":fontcolor=\(.):bordercolor=\(.)";""));",drawtext=fontcolor=white:bordercolor=white:borderw=\($b):fontfile=\($T):fontsize=\($f):y_align=font:expansion=none:text=" as $t|{O:0,G:1,V:2,D:3,W:4} as $src|i($j=="jp" and $js=="1";sort_by(i(.j=="";.n;.j)|gsub("ヴ";"ウ\n"));i($j=="ru" and $js=="1";sort_by(i(.p=="";.n;.p));i($mo=="1";sort_by($src[.o],.r,.u,.n|n(.));.)))|i($ms!="";map(select(.o|inside($ms+"O")));.)|map([i(.n|length>250;.m;.n)+".webp",(i($j=="jp" and .j!="";.j;i($j=="ru" and .p!="";.p;i($l=="1";.n;i(.m|length>0;.m;.n[:12]))))|gsub("\u0027";"\\\\\\\u0027")),.i1,.i2,.i3,.i4,i($u>0 and .n=="The Arcana";".22";i(.k==".";.k;" ")+(.i5|(2-length)*" "+.)),(.i,.a,.b,.c,.d,.x|.//""),.o,(.r,.u|n(.))]|i($u>0;. as $i|[[.[6]|i(.[:1]==".";.[1:]|0,n(.);n(0)|i($i[11]=="2";.,2*.;.))]|.,map(.*315/22|ceil/100)|join("-")] as $i|.[4]=$i[0]|.[5]="\($i[1])m"|.[2]=.[10]|.[3]=.[12];.))|(i($u==3;map(.[15])|max;$c)|n(3)) as $c|i($u==3;map(.[14])|max|n(.);length/$c|ceil) as $o|length as $num|(map(.[1]|length)|[max,20]|min) as $L|($W|n(2048)) as $W|($H|n(1489)) as $H|($H*4/$o) as $h|($p|n(1)) as $p|["bb0000","ffff00","0000bb","00bb00","004466","55bbff","bb00bb","dddddd"|.+i($p==0 and $u!=4;"36";"26")] as $G|[($s|n(2)),$L,(1,1,1,1|.+$p),3,(1,1,1),(1,1,1,1)] as $Xn|($Xn|i($u>0;i($u==4;.[:2]+[1,1,5,12]|i($p==0;.[:-1];.);.[:2]);.)) as $Xn|[0,0,(0,0,0,0),$p,(0,0),$p,(0,0,0),0] as $pn|(reduce range(0;$Xn|length+1) as $i([];.+[$Xn[:$i]+$pn[:$i]|add|n(0)])) as $xn|($xn[-1]*$c|$W*4/.) as $w|($Xn|map($w*.|t)) as $X|($pn|map($w*.|t)) as $pold|($xn|map($w*.|t)) as $x|reduce range(0;length) as $i(.;.[$i]|=[.,({x:(i($u==3;.[15];$i/$o|floor)*$x[-1]),y:(i($u==3;.[14];$i%$o)*$h|t),i:$i}|.yt="y=\(.y)+(\($h|t)\(i($u>0 and $u!=2 and $u!=4;"*0.78)";"\(i($u==2;"/2";""))-lh\(i($u>0 and $u!=2 and $u!=4;"*1.9";"")))\(i($u>0 and $u<4;"";"/2"))"))")])|. as $a|reduce (.[]|select(.[1].i>=0)) as $i(i($g!="0";reduce range(0;$c) as $i("";.+i($u==0;reduce range(0;$G|length) as $n("";.+",drawbox=\($x[-1]*$i+$x[2+$n]|t):0:\($X[2+$n]):ih:\($G[$n]):fill");i($u==4;",drawbox=\($x[-1]*$i+$x[4]|t):0:\($X[4]):ih:\($G[5]):fill";"")));"");.+($i|"\(.[1]|i(.x==0 and ($d|length>1);$t+"\(i(.i%2==1;"\u2014";"-")|.*500):borderw=\($b):bordercolor=\($d):fontcolor=\($d):y=\(.y-0.5*$h|t)";""))\(.[1]|i(.x==0 and .i%2==1;",drawbox=0:\(.y):iw:\($h|t):ffffff22:fill";""))\(reduce range(1;$X|length) as $n("";.+
    i($g=="0" or $u>0 or $i[1].i==0 or ($n|6<. and .<10|not) or ""==$i[0][$n];"";$i[1]|",drawbox=\(.x+$x[$n]|t):\(.y):\($X[$n]):\($h|t):\($G[$n-2]|.[:-2]+"77"):fill")+
    i(($i[1].i==0 or ($n|6<. and .<10|not)) and ""!=$i[0][$n] and i($u==4;$i[1].i>0;true);$i[0]|$t+i($u>0 and $u<4 and $n==1;reduce (10,12) as $n("";.+(i($j=="jp";["キュア","カスタム音"|.+j+$jp]|{C:.[0],X:.[1]};{C:"Cure",X:"SFX"}) as $m|$i[0][$n]|i(.=="";"";"\($m[.]):x=\($i[1].x|i($u!=2;.+$x[-1]*($n/2-5);.+$x[1]+($x[-1]-$x[1])*($n/2-5))|t)\(i($u!=3;i($n==12;"-tw";"");"+(\($X[1])-tw)/2")):y=\($i[1].i%$o|.*$h)\($n|color):fontsize=\($f*0.9)"+$t)));"")+"\\\\\($i[0][$n]|i($lc=="";.;i($n==1;gsub("(?<x>\\((?:Yellow|Green)\\))";.x|ascii_downcase);ascii_downcase))|esc|.+i($j=="jp" or $j=="ru";j+i($n==1;$jp;"");"")+i($n==1;":fontsize=\($f/([length/i($j=="jp";9.2;21),1]|max))";""))\(":x=\(i($u==1;$i[1].x;$i[1].x+$x[$n])|t)\(i($u!=3 and $n==1;"";i($u==4 and 3<$n and $n<6;"+\($X[$n])-tw";"+(\($X[$n])-tw)/2"))):\($i[1].yt)\($n|color)"|i($u>0 and $u<4 and $n==1;.+$t+($i[0]|i(.[4]=="0";"0";"\(.[4])\\,\(i(["OCR-B.woff","CyberpunkWaifus.ttf"]|contains([$T]);"";" "))\(.[5])"))+.+":fontsize=\($f*0.9):\(i($u==2;"y=\($i[1].y+($h/2)|t)";$i[1].yt+"+lh"+i($u==1;"";"/2")))";.))";"")
    ))"))|@sh "ffmpeg -hide_banner -v error -f lavfi -i color=s=\($W*4)x\($H*4) -i ice.webp -i blend.webp \($a[1:]|map("-i",.[0][0])) -/filter_complex \($i+".ffmpeg1") -map \("[v]") -vframes 1 -lossless 1 -n \($i+".webp")",("\("[0:v]"+.[1:],(
    i($u>0;
      i($u==2;
        i($j=="jp";"作成者：AutumnFiametta\\,\n17953648 & たけ：）\n凡例：酔いやすさ、\n気絶しないための最小身長"|split("\n")|map(.+j)|join("\n")+$jp+":borderw=0";"By AutumnFiametta\(i($l=="1";"";"\n")) & 17953648\nKey\\\\: Potency\\, min height\nto avoid passing out")
        +":fontsize=\($f*0.8)"
      ;
        i($u==4;
        i($j=="jp";["作成者\\\\: Autumn\\, 17953648 & たけ","凡例\\\\: キュア\\, カスタム音\\, 酔いやすさ\(i($p==0;"";"\\, 気絶しないための最小身長"))"|.+j+$jp];["By Autumn\n& 17953648","Key\\\\: Cure\\, SFX\\, Potency\(i($p==0;"";"\\, min height to avoid passing out"))"])
          |.[0]|=(.+":x=\($x[-1])-tw:fontsize=\($f*i($j=="jp";0.5;0.4))")|.[1]|=(.+":fontsize=\($f*i($p==0;i($j=="jp";0.45;0.7);0.5))\(i($j=="jp";":borderw=0";""))")|"%"+join($t)
        ;
          i($j=="jp";"作成者：Autumn\\,\n17953648 & たけ\n凡例：\n酔いやすさ、気絶\nしないための\n最小身長"|split("\n")|map(.+j)|join("\n")+$jp+":borderw=0";"By Autumn\n& 17953648\nKey\\\\:\nPotency\\,\nmin height\nto avoid\npassing out")
          +":fontsize=\($f*1.25)"))
          |i(.[:1]=="%";$t+.[1:]+":box=1:fontcolor=Black:bordercolor=Black";split(":")|reduce .[] as $i([[],[]];.[i(.[0]==[] or (.[1]==[] and (.[0][-1]|endswith("\\")));0;1)]|=(.+[$i]))|map(join(":"))|.[0]|=split("\n")|. as $a|.[0]|length as $l|reduce range(0;$l) as $i(",drawbox=0:0:\($x[-1]):\($h):ffffff:fill";.+$t+($a[0][$i]+($a[1]|i(.=="";.;":"+.))+":y=\($h/$l*$i):fontcolor=Black:bordercolor=Black")))
    ;
      $t+"Key\\\\: Ice Age Blend Cure Double SFX Origin:box=1:fontsize=\($f*0.38):fontcolor=Black:bordercolor=Black\($t)\(i($j=="jp" or $j=="ru";"By AutumnFiametta\\, 17953648 & "+i($j=="jp";"たけ：）";"Gureii")|.+j+$jp;"By AutumnFiametta & 17953648")):fontsize=\($f*0.38):y=lh")
    +i(($c*$o-$num)>0 and ($u==0 or $u==4);
      $t+"By Autumn\(i(($p==0 and $l!="1") or $j=="jp" or $j=="ru";"";"Fiametta")) & 17953648\(i($j=="jp" or $j=="ru";" & "+i($j=="jp";"たけ：）";"Gureii")|.+j+$jp;"")):x=\(($c-1)*$x[-1]+$x[1]/2):y=\($o-0.5|.*$h)-lh/2";"")+
      ",scale=\($W):-1[v],"),["I","i","A","a","B","b"] as $m|[i($u>0;empty;"[1:v]\(i($g=="0";"eq=brightness=0.5";"copy"))[I],color=s=240x240,geq=if(lt(abs(sqrt(pow(X-W/2\\,2)+pow(Y-H/2\\,2))-W*0.4)\\,0.10*W)\\,if(lt(mod(atan2(Y-H/2\\,X-W/2)+PI/4*0.7/2\\,PI/4)\\,PI/4*0.7)\\,255\\,0)\\,if(lt(abs(X-W/2)\\,0.10*W)\\,if(gt(Y/H\\,0.25)\\,if(lt(Y/H\\,0.5)\\,255\\,if(lt(abs(Y-H/2)\\,0.10*W)\\,255\\,0))\\,0)\\,if(lt(abs(Y-H/2)\\,0.10*W)\\,if(lt(X/W\\,0.75)\\,if(gt(X/W\\,0.5)\\,255\\,0)\\,0)\\,0))):128:128,geq=r=r(X\\,Y):g=r(X\\,Y)\(i($g=="0";"*0.9";"*0.7")):b=r(X\\,Y),format=rgba,colorkey,scale=64:64[A],color=s=240x240,format=rgba,geq=r=0:g=0:b=0:a=if(gt(sqrt(pow(X-W/2\\,2)+pow(Y-H/2\\,2))\\,W*0.5)\\,0\\,255),scale=64:64,split[a],scale=48:48[c],[A]split[o][A],[a][o]overlay[a],[a][c]overlay=(W-w)/2:(H-h)/2[a],[I]split[I],eq=brightness=1:saturation=0:gamma_r=0.1[o],[I]split[I],eq=brightness=-1:saturation=0,scale=0.8*iw:-2[i],[o][i]overlay=(W-w)/2:(H-h)/2[i],[2:v]split[B],geq=if(gt(lum(X\\,Y)\\,50)\\,255\\,0):128:128,pad=1.2*iw:ow/a:-1:-1,colorkey,negate,split[n],avgblur=5,geq=if(gt(alpha(X\\,Y)\\,0)\\,255\\,0):128:128:if(gt(alpha(X\\,Y)\\,0)\\,255\\,0)[o],[o][n]overlay=(W-w)/2:(H-h)/2,split[b][o],[B]scale=-1:ih*1.05:flags=neighbor,eq=brightness=0.1[B],[o][B]overlay=(W-w)/2:(H-h)/2[B]",($m[] as $i|"[\($i)]scale=if(a\\,min(\($w/4|t)\\,\($h/4|t)*a)\\,-1):if(a\\,-1\\,min(\($h/4|t)\\,\($w/4|t)/a)):flags=neighbor[\($i)]")),($a[1:]|range(0;length) as $i|.[$i]|. as $n|.[0]|i($u==2;($i+1) as $i|(.[6][1:]|[n(0),20]|min) as $k|{c:(.[10]!=""),k:$k,o:($n[0][6][:1]=="."),x:($x[-1]*($i/$o|floor)+$x[1]|./4),y:($n[1].y+$h/8*7|./4),w:($k|i(.>0;.;1)/20*$X[1]|./4),h:($h/8|./4|t)}|"nullsrc=s=\(.w|round)x\(.h|round),format=rgba,geq=\(i($g=="0";"255:128:128";"\(i(.c;170;i(.k>0;128;128))):\(i(.c;170;i(.k>0;108*.k/20;255))):\(i(.c;0;i(.k>0;255*.k/20;255)))")):\(i(.k>1;"if(lt(mod(X\\,(W/\(.k)))/(W/\(.k))\\,0.8)\\,\(i(.o;"if(between(X\\,2\\,W-2)\\,if(between(Y\\,2\\,H-2)\\,0\\,200)\\,200)";"200"))\\,if(gte(X\\,W-2)\\,200))";i(.o;"if(between(X\\,2\\,W-2)\\,if(between(Y\\,2\\,H-2)\\,0\\,200)\\,200)";200)))[o],[v][o]overlay=\(.x):\(.y):format=rgb[v],"//",drawbox=\(.x):\(.y):\(.w):\(.h):ff000022:fill";"")+"[\($i+3):v]scale=if(a\\,min(\(i($u==3;$W/$c;$X[0]/4)|t)\\,\(i($u==3;$H/$o;$h/4)*i($u==1;0.78;1)|t)*a)\\,-1):if(a\\,-1\\,min(\(i($u==3;$H/$o;$h/4)*i($u==1;0.78;1)|t)\\,\(i($u==3;$W/$c;$X[0]/4)|t)/a)):flags=neighbor[o],[v][o]overlay=\(i($u==3;$W/$c|.*($n[0][15]);$n[1].x+$x[0]|./4))+(\(i($u==3;$H/$o;$X[0]/4))-w)/2:\($n[1].y/4)+(\($h/4*i($u==1;0.78;1)|t)-h)/2:format=rgb[v]"+i($u>0;"";reduce range(0;3) as $i("";i($n[0][7+$i]!="";.+",[\($n[0][7+$i]|.+"]split["+.)][o],[v][o]overlay=\($n[1].x+$x[7+$i]|./4|t)+(\($X[7+$i]/4)-w)/2:\($n[1].y/4)+(\($h/4|t)-h)/2:format=rgb[v]";.)))),i($u>0;empty;$m[]|"[\(.)]nullsink")]|join(","))"|stderr|empty)' 2> "$3.ffmpeg1"|tee "$3.ffmpeg"; }|bash
  chmod 644 "$3".{ffmpeg,ffmpeg1,webp}
  [[ -s "$3.ffmpeg" && -s "$3.ffmpeg1" && -s "$3.webp" ]]||exit 1
  [[ $NOCACHE ]]&&exit # cache
  b h n c "${3##*/}".{ffmpeg,ffmpeg1,webp} # cache
else
  printf '%q [old dir] [dir] [force update|(0)/1]\n%q [old dir] [dir] [audio|tmp]\n%q [old dir] [dir] [file prefix] [borderw] [fontsize]\n  [full name|(0)/1] [color|0/(1)] [columns|3] [image size|2]\n  [customer|(0)/1: visual/2: balanced/4: text]\n  [gap|0/(1)] [width|2048] [height|1489]\n%q track [file]...\n%q [bitrate|0] [tracklist file] [output] [file]...\n%q [image] [output]\n%q [video] [audio] [output]\n%q [dir]/[fontid (fonts.bunny.net)].css\n%q [output] [fonts to merge]...\n' "${0##*/}"{,,,,,,,,}
fi
