From 9ca11eb0a923fbdf0178d9aec45f50db155af015 Mon Sep 17 00:00:00 2001 From: Adithya Nair Date: Thu, 18 May 2023 20:09:34 +0530 Subject: [PATCH] download wallpaper and echo out the path to downloaded image --- packages/scripts/wallhaven.sh | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) mode change 100644 => 100755 packages/scripts/wallhaven.sh diff --git a/packages/scripts/wallhaven.sh b/packages/scripts/wallhaven.sh old mode 100644 new mode 100755 index cae0e8e..193127c --- a/packages/scripts/wallhaven.sh +++ b/packages/scripts/wallhaven.sh @@ -2,20 +2,17 @@ set -eu -wallpaper() { - FILENAME="/tmp/image-${RANDOM}" +DIR="${1:-/tmp}" +mkdir -p "$DIR" - notify-send -r 9897 -i information -t 1000 "Wallpapers" "Downloading..." - URL="https://wallhaven.cc/api/v1/search?categories=100&purity=100&atleast=1920x1080&ratios=16x9&sorting=random" - ID="$(curl --silent $URL | jq -r '.data[0].id')" - IMAGE_URL="$(curl --silent "https://wallhaven.cc/api/v1/w/$ID" | jq -r '.data.path')" +notify-send -r 9897 -i information -t 1000 "Wallpapers" "Downloading..." +URL="https://wallhaven.cc/api/v1/search?categories=100&purity=100&atleast=1920x1080&ratios=16x9&sorting=random" +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" - curl --silent -L --output "$FILENAME" "$IMAGE_URL" - echo $FILENAME -} - -swww query || swww init -convert "$(wallpaper)" "/tmp/wallpaper.jpg" && swww img "/tmp/wallpaper.jpg" -convert "$(wallpaper)" "/tmp/lockpaper.jpg" - -notify-send -r 9897 -i information -t 1000 "Wallpaper" "Wallpaper changed."