| 1 | #!/bin/sh |
| 2 | # subscription pass on a 6h cycle — but if youtube has bot-walled the ip |
| 3 | # ("sign in to confirm you're not a bot"), back off for a whole day instead |
| 4 | # of hammering it every cycle, which prolongs the wall. |
| 5 | while true; do |
| 6 | started=$(date +%s) |
| 7 | ytdl-sub --config /config-yt/config.yaml sub /yt-config/subscriptions.yaml 2>&1 | tee /tmp/last-pass.log |
| 8 | finished=$(date +%s) |
| 9 | if grep -q "confirm you.re not a bot" /tmp/last-pass.log; then |
| 10 | echo "[archive-loop] bot wall detected; sleeping 24h" |
| 11 | printf '{"started":%s,"finished":%s,"walled":true,"next":%s}\n' "$started" "$finished" "$((finished + 86400))" > /config/archive-status.json.tmp |
| 12 | mv /config/archive-status.json.tmp /config/archive-status.json |
| 13 | sleep 86400 |
| 14 | else |
| 15 | printf '{"started":%s,"finished":%s,"walled":false,"next":%s}\n' "$started" "$finished" "$((finished + 21600))" > /config/archive-status.json.tmp |
| 16 | mv /config/archive-status.json.tmp /config/archive-status.json |
| 17 | sleep 21600 |
| 18 | fi |
| 19 | done |