← back to Fantasea Consulting
poll-videos.sh
24 lines
#!/bin/bash
# Poll the 5 HeyGen renders and download each when complete.
export HEYGEN_API_KEY=$(grep -iE "HEYGEN" ~/Projects/secrets-manager/.env | head -1 | cut -d= -f2- | tr -d '"'"'"' ')
cd /Users/macstudio3/Projects/fantasea-consulting
mkdir -p public/videos
DONE=0
for try in $(seq 1 60); do # up to ~20 min
ALL=1
while read k id; do
out="public/videos/heygen-$k.mp4"
[ -s "$out" ] && continue
ALL=0
json=$(heygen video get "$id" 2>/dev/null)
st=$(echo "$json" | node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{try{const j=JSON.parse(d);const o=j.data||j;console.log(o.status||"?")}catch(e){console.log("?")}})')
if [ "$st" = "completed" ] || [ "$st" = "success" ]; then
url=$(echo "$json" | node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{try{const j=JSON.parse(d);const o=j.data||j;console.log(o.video_url||o.video_url_caption||"")}catch(e){console.log("")}})')
if [ -n "$url" ]; then curl -s -L -o "$out" "$url"; echo "$(date +%T) downloaded $k ($(stat -f%z "$out" 2>/dev/null||echo 0) b)"; fi
fi
done < videos-src/manifest.txt
[ "$ALL" = "1" ] && { echo "$(date +%T) ALL 5 DOWNLOADED"; DONE=1; break; }
sleep 20
done
echo "poller exit (done=$DONE)"