Skip to content

Instantly share code, notes, and snippets.

@elderica
Last active August 22, 2024 11:25
Show Gist options
  • Save elderica/37378bc8265546339084d095797de56c to your computer and use it in GitHub Desktop.
Save elderica/37378bc8265546339084d095797de56c to your computer and use it in GitHub Desktop.
Download wallpapers from Bing. This script depends curl and jq.
#!/bin/sh
### Usage:
### $ env RESOLUTION=UHD NDAYSAGO=1 SAVETO=$HOME/Bing sh download_bing_wallpaper.sh
set -euo pipefail
RESOLUTION=${RESOLUTION:-1920x1080} # Possible values: 1920x1080, 1366x768, UHD
NDAYSAGO=${NDAYSAGO:-0}
SAVETO=${SAVETO:-"${HOME}""/Pictures/Bing/"$(date -v -"${NDAYSAGO}"d '+%Y%m%d')}
mkdir -p "${SAVETO}"
API_URL="http://www.bing.com/HPImageArchive.aspx?format=js&n=10&idx=${NDAYSAGO}"
curl -sSL "${API_URL}" |
jq -c '.images[] | {urlbase, copyright, title}' |
while read -r entry ; do
urlbase=$(printf '%s' "${entry}" | jq -r '.urlbase')
basename="${urlbase#/th?id=}"
imgfile="${basename}_${RESOLUTION}.jpg"
descfile="${basename}.txt"
[ -f "${SAVETO}/${descfile}" ] || (printf '%s' "${entry}" | jq -r '.copyright, .title' | tee "${SAVETO}/${descfile}")
[ -f "${SAVETO}/${imgfile}" ] || curl -sSLo "${SAVETO}/${imgfile}" "https://www.bing.com/th?id=${imgfile}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment