Created
March 23, 2025 13:18
-
-
Save elderica/a1c03b18a4a33a2cda0b10ec90a2ac15 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
### Usage: | |
### $ env RESOLUTION=UHD NDAYSAGO=1 COUNT=10 MARKET=ja-JP SAVETO=$HOME/Bing sh download_bing_wallpaper.sh | |
set -euo pipefail | |
RESOLUTION=${RESOLUTION:-1920x1080} # Possible values: 1920x1080, 1366x768, UHD | |
NDAYSAGO=${NDAYSAGO:-0} | |
COUNT=${COUNT:-1} | |
MARKET=${MARKET:-ja-JP} | |
SAVETO=${SAVETO:-"${HOME}""/Pictures/Bing"} | |
API_URL="http://www.bing.com/HPImageArchive.aspx" | |
mkdir -p "${SAVETO}" | |
curl -sSLG -d 'format=js' -d "resolution=${RESOLUTION}" -d "mkt=${MARKET}" -d "idx=${NDAYSAGO}" -d "n=${COUNT}" "${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