#!/bin/bash
## You can get the cookies.txt using the browser extension cookies.txt
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

last_updated=$(cat .last_updated)
echo $(date +%s) > .last_updated
echo "Running from $last_updated"

podman run \
  --rm \
  -v "$SCRIPT_DIR:/gallery-dl/:Z" \
  -v "$HOME/Downloads/cookies.txt:/cookies.txt:Z" \
  -v "$SCRIPT_DIR/gallery-dl.conf:/etc/gallery-dl.conf:Z" \
  -it \
  gallery-dl:latest \
  --sleep 0-2 \
  --verbose \
  --cookies "/cookies.txt" \
  --input-file "/gallery-dl/target-urls" \
  --write-log "/gallery-dl/logs/$(date "+%Y-%m-%d %T").log" \
  --write-metadata \
  --write-info-json \
  --write-tags \
  --date-after "$last_updated"

mullvad-exclude podman run \
  --rm \
  -v "$SCRIPT_DIR:/gallery-dl/:Z" \
  -v "$HOME/Downloads/cookies.txt:/cookies.txt:Z" \
  -v "$SCRIPT_DIR/gallery-dl.conf:/etc/gallery-dl.conf:Z" \
  -it \
  gallery-dl:latest \
  --sleep 1-5 \
  --verbose \
  --cookies "/cookies.txt" \
  --input-file "/gallery-dl/non-vpn-target-urls" \
  --write-log "/gallery-dl/logs/$(date "+%Y-%m-%d %T").log" \
  --write-metadata \
  --write-info-json \
  --write-tags \
  --date-after "$last_updated"

bash "$SCRIPT_DIR/download-reddit" -u BindOnEquip
