#!/bin/bash

echo "URL: $1"
echo "file: ${2:-file.png}"

curl --request POST \
  --url https://api.firecrawl.dev/v2/scrape \
  --header 'Authorization: Bearer fc-6f8bbea8bd684617b7958c3d5b2531bc' \
  --header 'Content-Type: application/json' \
  --data '
{
  "url": "'"$1"'",
  "formats": [
    "screenshot"
  ],
  "onlyMainContent": true,
  "onlyCleanContent": true,
  "maxAge": 172800000,
  "minAge": 123,
  "headers": {},
  "waitFor": 0,
  "mobile": false,
  "skipTlsVerification": true,
  "timeout": 60000,
  "actions": [
    {
      "type": "wait",
      "milliseconds": 2
    }
  ],
  "location": {
    "country": "US",
    "languages": [
      "en-US"
    ]
  },
  "removeBase64Images": true,
  "blockAds": true,
  "proxy": "auto",
  "storeInCache": true,
  "lockdown": false,
  "redactPII": false,
  "zeroDataRetention": false
}
' \
| jq -r .data.screenshot \
| wget -O "${2:-file.png}" -i -
