2023-05-16 00:19:04 +05:30
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2023-05-18 20:09:34 +05:30
|
|
|
DIR="${1:-/tmp}"
|
|
|
|
mkdir -p "$DIR"
|
2023-05-16 00:19:04 +05:30
|
|
|
|
2023-10-13 12:36:02 +05:30
|
|
|
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
|
2023-10-13 13:23:05 +05:30
|
|
|
if [ ! -e $CONFIG_DIR/wallpaper_config ]; then
|
|
|
|
echo '{"tags":null,"categories":"100","purity":"100"}' | jq > $CONFIG_DIR/wallpaper_config
|
|
|
|
fi
|
|
|
|
|
|
|
|
TAGS="$(cat $CONFIG_DIR/wallpaper_config | jq -r '.tags // empty')"
|
2023-10-13 12:36:02 +05:30
|
|
|
if [ -n "$TAGS" ]; then
|
|
|
|
TAGS="q=$TAGS&"
|
|
|
|
fi
|
|
|
|
|
2023-10-13 13:23:05 +05:30
|
|
|
CATEGORIES="$(cat $CONFIG_DIR/wallpaper_config | jq -r '.categories // empty')"
|
|
|
|
if [ -n "$CATEGORIES" ]; then
|
|
|
|
CATEGORIES="categories=$CATEGORIES&"
|
|
|
|
fi
|
|
|
|
|
|
|
|
PURITY="$(cat $CONFIG_DIR/wallpaper_config | jq -r '.purity // empty')"
|
|
|
|
if [ -n "$PURITY" ]; then
|
|
|
|
PURITY="purity=$PURITY&"
|
|
|
|
fi
|
|
|
|
|
|
|
|
WALLHAVEN_API_KEY="$(secret-tool lookup application wallhaven-api-key)"
|
2023-10-13 13:25:55 +05:30
|
|
|
if [ -n "$WALLHAVEN_API_KEY" ]; then
|
2023-10-13 13:23:05 +05:30
|
|
|
WALLHAVEN_API_KEY="apikey=$WALLHAVEN_API_KEY&"
|
|
|
|
fi
|
|
|
|
|
2023-05-18 20:09:34 +05:30
|
|
|
notify-send -r 9897 -i information -t 1000 "Wallpapers" "Downloading..."
|
2023-10-13 13:25:55 +05:30
|
|
|
URL="https://wallhaven.cc/api/v1/search?${WALLHAVEN_API_KEY}${TAGS}${CATEGORIES}${PURITY}atleast=3840x2160&ratios=16x9&sorting=random"
|
2023-05-18 20:09:34 +05:30
|
|
|
ID="$(curl --silent "$URL" | jq -r '.data[0].id')"
|
|
|
|
IMAGE_META=$(curl --silent "https://wallhaven.cc/api/v1/w/$ID")
|
|
|
|
IMAGE_URL="$(echo "$IMAGE_META" | jq -r '.data.path')"
|
|
|
|
IMAGE_ID="$(echo "$IMAGE_META" | jq -r '.data.id')"
|
|
|
|
FILENAME="wallhaven-$IMAGE_ID"
|
|
|
|
curl --silent -L --output "/tmp/$FILENAME" "$IMAGE_URL"
|
|
|
|
convert "/tmp/$FILENAME" "$DIR/$FILENAME.jpg"
|
|
|
|
echo "$DIR/$FILENAME.jpg"
|
2023-05-16 00:19:04 +05:30
|
|
|
|