Tim's blah blah blah

Download Kidsconnect Konnect ouderportaal photos by date

Kidsconnect (kidskonnect.nl) Konnect ouderportaal (kidskonnect.nl) has photos of my kid, good news: I can download all photos from the portal. Bad news: they strip all metadata (including date), resulting in a set of photos with random filenames in random order. Good news: they allow for date selection in their download photos menu. Below I automate this process a bit.

Log in with regular browser, track headers:

Request:

POST /restservices-parent/photos/download/v2 HTTP/1.1
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en;q=0.9
Authorization: Bearer TOKENID.AUTHORIZATIONID
Connection: keep-alive
Content-Length: 244
Content-Type: application/json
Cookie: __Host-refresh_token=TOKENID.COOKIEID
Host: partou.ouderportaal.nl
Origin: https://partou.ouderportaal.nl
Referer: https://partou.ouderportaal.nl/parent/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15
X-Client-Name: ParentUI
X-Client-Version: 3.45.2

Request Data:

{"uniquifier":"UNIQUEID","periodCode":"10","fromDate":"2024-07-01T20:37:00.000Z","toDate":"2024-07-23T20:37:48.130Z","selectOwnPeriod":true,"periodStart":"2024-07-01T20:37:00.000Z","periodEnd":"2024-07-23T20:37:48.130Z"}

Replay in curl to check if it works. Perhaps some parameters are superfluous, but they don’t hurt so I kept them.

curl \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Encoding: gzip, deflate, br'\
  -H 'Accept-Language: en-GB,en;q=0.9'\
  -H 'Authorization: Bearer TOKENID.AUTHORIZATIONID'\
  -H 'Connection: keep-alive'\
  -H 'Content-Length: 244'\
  -H 'Content-Type: application/json'\
  -H 'Cookie: __Host-refresh_token=TOKENID.COOKIEID'\
  -H 'Host: partou.ouderportaal.nl'\
  -H 'Origin: https://partou.ouderportaal.nl'\
  -H 'Referer: https://partou.ouderportaal.nl/parent/'\
  -H 'Sec-Fetch-Dest: empty'\
  -H 'Sec-Fetch-Mode: cors'\
  -H 'Sec-Fetch-Site: same-origin'\
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_12) AppleWebKit/1337.1.12 (KHTML, like Gecko) Version/20.1 Safari/1337.1.12'\
  -H 'X-Client-Name: ParentUI'\
  -H 'X-Client-Version: 3.45.2'\
  --request POST \
  --data '{"uniquifier":"UNIQUEID","periodCode":"10","fromDate":"2024-07-01T20:37:00.000Z","toDate":"2024-07-23T20:37:48.130Z","selectOwnPeriod":true,"periodStart":"2024-07-01T20:37:00.000Z","periodEnd":"2024-07-23T20:37:48.130Z"}' \
  https://partou.ouderportaal.nl/restservices-parent/photos/download/v2

Now script and automate to run over requested dates, either use sleep 10 to automatically request new photos every 10s or use read to continue upon key press.

fromdate=2024-01-01;
while true; do
  todate=$(gdate -d"${fromdate}+1week" -Idate);
  echo $fromdate to $todate
  mkdir $fromdate
  curl \
    -H 'Accept: application/json, text/plain, */*' \
    -H 'Accept-Encoding: gzip, deflate, br'\
    -H 'Accept-Language: en-GB,en;q=0.9'\
    -H 'Authorization: Bearer TOKENID.AUTHORIZATIONID'\
    -H 'Connection: keep-alive'\
    -H 'Content-Length: 244'\
    -H 'Content-Type: application/json'\
    -H 'Cookie: __Host-refresh_token=TOKENID.COOKIEID'\
    -H 'Host: partou.ouderportaal.nl'\
    -H 'Origin: https://partou.ouderportaal.nl'\
    -H 'Referer: https://partou.ouderportaal.nl/parent/'\
    -H 'Sec-Fetch-Dest: empty'\
    -H 'Sec-Fetch-Mode: cors'\
    -H 'Sec-Fetch-Site: same-origin'\
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_12) AppleWebKit/1337.1.12 (KHTML, like Gecko) Version/20.1 Safari/1337.1.12'\
    -H 'X-Client-Name: ParentUI'\
    -H 'X-Client-Version: 3.45.2'\
    --request POST \
    --data '{"uniquifier":"UNIQUEID","periodCode":"10","fromDate":"'${fromdate}'T19:18:00.000Z","toDate":"'${todate}'T19:18:00.000Z","selectOwnPeriod":true,"periodStart":"'${fromdate}'T19:18:00.000Z","periodEnd":"'${todate}'T19:18:00.000Z"}' \
    https://partou.ouderportaal.nl/restservices-parent/photos/download/v2
  echo
  read
  echo sleep 10
  fromdate=${todate}
done

Optionally build in a date test to stop at a certain time automatically:

  todate_sec=$(gdate -d ${todate} +%s)
  cond_sec=$(gdate -d 2023-10-16 +%s)
  if [ ${todate_sec} -ge ${cond_sec} ];
  then
    echo "Finished at ${todate}"
      break
  fi  

Then repeat like a monkey 100 times:

  1. start script
  2. open mail
  3. click download
  4. move download to target directory
  5. repeat

Now that the photos are in directories by date, we can tag dates with jhead or exiftool:

for dir in *; do 
  echo $dir
  thisdate=$(echo $dir | tr -d \-)
  find ${dir} -type f \( -iname \*.jpeg -o -iname \*.mp4 \) | xargs touch -t ${thisdate}1200
  exiftool -recurse "-CreationDate<FileModifyDate" "-DateTimeOriginal<FileModifyDate" -P  -ext MP4 "${dir}"
  exiftool -recurse "-DateTimeOriginal<FileModifyDate" -P  -ext JPEG "${dir}"
done

Fix a few files manually because the dates are off somehow:

exiftool -wm w -time:all=2023:01:18:12:00:00+01:00 uuid-uuid-uuid-uuid-uuid-video-uuid.mp4

Copy (not move to allow retry) back files from subdirectories into one large directory (as ons sees fit). Use cp -a to preserve modification date.

find . -type f \( -iname \*.jpeg -o -iname \*.mp4 \) -exec cp -a {} . \;

If the result is satisfactory, delete the dated subdirectories.

#E-Mail #Mac #Curl #Networking