-
-
Save lmaertin/58c5566b3c69a159e393389241f3db76 to your computer and use it in GitHub Desktop.
Script to download Photos from Synology Photo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
#Script to download photos from a public shared album in Synology Photos | |
# | |
#Setup: | |
#0) sudo apt install jq | |
#1) Share an album as "Anyone with link can view" in Synology Photos | |
#2) Copy AlbumId (end of the Link) | |
#3) Add host and album Id below | |
#4) run manually or via cronjob | |
# | |
# Example for cronjob: | |
# 1) run crontab -e | |
# 2) add this line : | |
# #download new photos every day at 0.00h | |
# 0 0 * * * /home/pi/syno-photos-downloader/syno-photos-downloader.sh | |
# 3) Save and close | |
# | |
# Note curl is set to silent mode, but still shows errors | |
# | |
# based on: | |
# https://daanmiddendorp.com/tech/2022/02/14/new-destination-for-my-broken-kindle.html | |
# https://github.com/landgenoot/kindle-synology-photos-photoframe/blob/main/src/refresh.sh | |
HOST="https://TODO:TODO" | |
ALBUMID="TODO" | |
EXPORTDIR="photos" | |
#variable to cache photo filenames in album | |
PHOTONAMES="" | |
#create output dir if not existing | |
mkdir -p ${EXPORTDIR} | |
link=${HOST}'/mo/sharing/'${ALBUMID} | |
cookie=$(curl -sS -k "${link}" -i | grep sharing_sid) | |
cookie="${cookie#*:}" | |
cookie="${cookie%;*}" | |
base_url="${link%/*}" | |
album_code="${link##*/}" | |
album=$(curl -sS -k "${base_url}/webapi/entry.cgi?" -X POST \ | |
-H "x-syno-sharing: ${album_code}" \ | |
-H "Cookie: ${cookie}" \ | |
-d 'offset=0&limit=1000&api="SYNO.Foto.Browse.Item"&method="list"&version=1 -b cookies.txt') | |
#number of photos in album | |
length=$(($(echo "${album}" | jq -r '.data[] | length ')-1)) | |
#get all images (if not existing) | |
#echo -ne "Downlading $((${length}+1)) photos: " | |
for ((i=0;i<=length;i++)); do | |
#show progress | |
#echo -ne "$((${i}+1)) " | |
id=$(echo "${album}" | jq -r ".data[] | .[${i}] | .id ") | |
#cache filename | |
PHOTONAMES="${PHOTONAMES}${id}\|" | |
#download photo if not yet existing in export dir | |
if [ ! -f "${EXPORTDIR}/${id}.jpg" ]; then | |
#curl -sS -k "${base_url}/webapi/entry.cgi/20210807_144336.jpg" -G | |
echo "Downloading new photo ${id}.jpg..." | |
curl -sS -k "${base_url}/webapi/entry.cgi/20210807_144336.jpg" -G \ | |
-H "Cookie: ${cookie}" \ | |
-d "id=${id}" -d "cache_key=\"35336_1628372812\"&type=\"unit\"&size=\"xl\"&passphrase=\"${album_code}\"&api=\"SYNO.Foto.Thumbnail\"&method=\"get\"&version=1&_sharing_id=\"${album_code}\"" \ | |
-o "${EXPORTDIR}/${id}.jpg" | |
fi | |
done | |
#delete orphaned photos, i.e., no longer in album | |
len=${#PHOTONAMES} | |
if [ ${len} -gt 2 ] | |
then | |
#remove \| at the end of the string | |
PHOTONAMES=${PHOTONAMES::len-2} | |
cd ${EXPORTDIR} | |
#get inversed list of photos in folder but NOT in PHOTONAMES | |
PHOTONAMESORPHANED=$(ls | grep -v "${PHOTONAMES}") | |
if [ ${#PHOTONAMESORPHANED} -gt 0 ] | |
then | |
echo "Remove orphaned photos:" | |
echo "${PHOTONAMESORPHANED}" | |
#rm -r ${PHOTONAMESORPHANED} | |
rm -r `ls | grep -v "${PHOTONAMES}"` | |
fi | |
cd .. | |
fi | |
echo "Photo download done." |
Sorry, no further idea
Kommando nicht gefunden.
/mo/sharingxxxx.xxxx.me:xxx
This seems to be wrong
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copying from Line 36 works. It automatically adds "#/" while its connecting to my SN.
I'm using Debian GNU/Linux 11 (bullseye)"
bash syno-photos-downloader.sh
syno-photos-downloader.sh: Zeile 2: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 24: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 27: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 29: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 32: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 35: $'\r': Kommando nicht gefunden.
curl: (3) URL using bad/illegal format or missing URL
syno-photos-downloader.sh: Zeile 42: $'\r': Kommando nicht gefunden.
/mo/sharingxxxx.xxxx.me:xxx
syno-photos-downloader.sh: Zeile 44: $'\r': Kommando nicht gefunden.
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
syno-photos-downloader.sh: Zeile 49: -H: Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 50: -H: Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 51: -d: Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 49: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 52: $'\r': Kommando nicht gefunden.
syno-photos-downloader.sh: Zeile 55: Syntaxfehler beim unerwarteten Symbol »$'do\r'«
'yno-photos-downloader.sh: Zeile 55: `for ((i=0;i<=length;i++)); do