Skip to content

Instantly share code, notes, and snippets.

@blakelead
Last active December 12, 2019 21:12
Show Gist options
  • Save blakelead/e527c46e7d718d7016c6514cd5067ae6 to your computer and use it in GitHub Desktop.
Save blakelead/e527c46e7d718d7016c6514cd5067ae6 to your computer and use it in GitHub Desktop.
Pause/Resume downloads for Synology Download Station
#!/bin/bash
NAS_URI=*.*.*.*:5000
LOGIN=user
PASSWORD=mypassword
ACTION=$1
if [[ "$ACTION" != "resume" && "$ACTION" != "pause" ]]; then
echo 'No action specified'
echo 'Usage: ./dl_station.sh pause/resume'
exit 1
fi
echo 'Authenticating...'
AUTH_RES=$(curl -s "http://${NAS_URI}/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=${LOGIN}&passwd=${PASSWORD}&session=DownloadStation&format=sid")
echo $AUTH_RES; echo
SUCCESS=$(echo $AUTH_RES | jq -r '.success')
if [[ "$SUCCESS" != "true" ]]; then
echo 'Error during authentication'
exit 1
fi
echo 'Getting auth token...'
SID=$(echo $AUTH_RES | jq -r '.data.sid')
echo $SID; echo
echo 'Retrieving Download station data...'
DL_RES=$(curl -s "http://${NAS_URI}/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=list" -H "Cookie: id=${SID}")
echo $DL_RES; echo
SUCCESS=$(echo $DL_RES | jq -r '.success')
if [[ "$SUCCESS" != "true" ]]; then
echo 'Error during data retrieval'
exit 1
fi
echo 'Getting download list...'
DL_LIST=$(echo $DL_RES | jq -r '.data.tasks | map(.id) | join(",")')
echo $DL_LIST; echo
if [[ "$DL_LIST" = "" ]]; then
echo 'Empty download list'
exit 0
fi
echo "Download ${ACTION} requested..."
DL_RES=$(curl -s "http://${NAS_URI}/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=${ACTION}&id=${DL_LIST}" -H "Cookie: id=${SID}")
echo $DL_RES; echo
SUCCESS=$(echo $DL_RES | jq -r '.success')
if [[ "$SUCCESS" = "true" ]]; then
echo 'Action succeeded'
else
echo "Action failed"
exit 1
fi
@blakelead
Copy link
Author

Use it like this:

./dl_station.sh pause
# or
./dl_station.sh resume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment