#!/bin/sh
# requires gallery-dl + exiftool and a netscape-format pinterest cookies file

PINTEREST_USER="your-pinterest-username"
COOKIES_FILE="/path/to/pinterest-cookies.txt"
OUT_DIR="/path/to/output"
LOG_FILE="/tmp/pinsync.log"

[ -f "$COOKIES_FILE" ] || exit 0
: > "$LOG_FILE"

sync() {
  gallery-dl --cookies "$COOKIES_FILE" \
    --download-archive "$OUT_DIR/$2/.archive.db" \
    -D "$OUT_DIR/$2" -f "{filename}.{extension}" \
    --exec "exiftool -all= -tagsfromfile @ -icc_profile -orientation -P -overwrite_original -q {}" \
    "https://www.pinterest.com/$PINTEREST_USER/$1/" >> "$LOG_FILE" 2>&1
}

# one line per board: sync <board-slug> <folder-name>
sync example-board photos
sync another-board "more photos"

cp "$LOG_FILE" "$OUT_DIR/.pinsync.log"
# src: ezra, contact: ezkru69@mail.com