#!/usr/bin/env bash set -euo pipefail THREAD_ID="${THREAD_ID:-1455993943471820842}" OUT_DIR="${OUT_DIR:-$PWD/thread}" HTML="$OUT_DIR/export.html" URLS="$OUT_DIR/urls.txt" # aria2c input file: one URL per line # Token from env, otherwise prompt (input hidden) if [[ -z "${DISCORD_TOKEN:-}" ]]; then read -rsp "Discord token: " DISCORD_TOKEN echo fi mkdir -p "$OUT_DIR" # 1. Export the thread to HTML docker run --rm --user "$(id -u):$(id -g)" \ -v "$OUT_DIR:/out" \ tyrrrz/discordchatexporter:stable export \ -t "$DISCORD_TOKEN" -c "$THREAD_ID" -f HtmlDark -o /out/export.html unset DISCORD_TOKEN # 2. Find base64 strings starting with "https://", then decode them grep -oP 'aHR0cHM6Ly[89][A-Za-z0-9+/_-]*' "$HTML" \ | sort -u \ | while read -r s; do s=$(printf '%s' "$s" | tr '_-' '/+' | tr -d '=') while (( ${#s} % 4 )); do s="$s="; done printf '%s' "$s" | base64 -d 2>/dev/null | tr -d '\r\n' || true echo done \ | grep -E '^https://[[:graph:]]+$' \ | awk '!seen[$0]++' > "$URLS" echo "Found $(wc -l < "$URLS") URLs -> $URLS" echo "Download with: aria2c -i \"$URLS\" -d \"$OUT_DIR/downloads\""