#!/usr/bin/env bash
set -euo pipefail

#CLI="TwitchDownloaderCLI"
CLI=(dotnet /zfszero/fuwa/TwitchDownloader/TwitchDownloaderCLI/out/TwitchDownloaderCLI.dll)
files=(
  "all_videos.txt"
  "clips.txt"
  "highlights.txt"
  "past_broadcasts.txt"
  "uploads.txt"
)

for f in "${files[@]}"; do
  [[ -f "$f" ]] || continue
  dir="${f%.txt}"
  mkdir -p "$dir"
  while IFS= read -r url; do
    [[ -z "$url" ]] && continue
    id="${url##*/}"
    if [[ "$url" == *"/clip/"* ]]; then
      "${CLI[@]}" clipdownload --id "$url" --output "$dir/${id}.mp4"
    else
      "${CLI[@]}" videodownload --id "$url" --output "$dir/${id}.mp4"
    fi
    "${CLI[@]}" chatdownload --id "$url" --output "$dir/${id}_chat.json"
  done < "$f"
done
