configurable wallpapers ftw

This commit is contained in:
Adithya 2023-10-13 13:23:05 +05:30
parent 0743307cac
commit 33e2f8a23a
Signed by: adtya
GPG key ID: 48FC9915FFD326D0
2 changed files with 23 additions and 3 deletions

View file

@ -12,6 +12,7 @@
jq, jq,
curl, curl,
ytfzf, ytfzf,
libsecret
}: }:
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
pname = "scripts"; pname = "scripts";
@ -45,7 +46,7 @@ stdenvNoCC.mkDerivation {
wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [libnotify rofi-wayland hyprland]} wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [libnotify rofi-wayland hyprland]}
wrapProgram $out/bin/tmux-sessions --prefix PATH : ${lib.makeBinPath [tmux kitty rofi-wayland]} wrapProgram $out/bin/tmux-sessions --prefix PATH : ${lib.makeBinPath [tmux kitty rofi-wayland]}
wrapProgram $out/bin/chpaper --prefix PATH : ${lib.makeBinPath [imagemagick libnotify swww]} wrapProgram $out/bin/chpaper --prefix PATH : ${lib.makeBinPath [imagemagick libnotify swww]}
wrapProgram $out/bin/wallhaven --prefix PATH : ${lib.makeBinPath [imagemagick libnotify jq curl]} wrapProgram $out/bin/wallhaven --prefix PATH : ${lib.makeBinPath [imagemagick libnotify jq curl libsecret]}
wrapProgram $out/bin/youtube --prefix PATH : ${lib.makeBinPath [kitty ytfzf rofi-wayland]} wrapProgram $out/bin/youtube --prefix PATH : ${lib.makeBinPath [kitty ytfzf rofi-wayland]}
''; '';
} }

View file

@ -6,13 +6,32 @@ DIR="${1:-/tmp}"
mkdir -p "$DIR" mkdir -p "$DIR"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}" CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
TAGS="$(<$CONFIG_DIR/wallpaper_tags)" 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')"
if [ -n "$TAGS" ]; then if [ -n "$TAGS" ]; then
TAGS="q=$TAGS&" TAGS="q=$TAGS&"
fi fi
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)"
if [ -n "$WALLHAVEN_API_KEY"]; then
WALLHAVEN_API_KEY="apikey=$WALLHAVEN_API_KEY&"
fi
notify-send -r 9897 -i information -t 1000 "Wallpapers" "Downloading..." notify-send -r 9897 -i information -t 1000 "Wallpapers" "Downloading..."
URL="https://wallhaven.cc/api/v1/search?${TAGS}categories=100&purity=100&atleast=3840x2160&ratios=16x9&sorting=random" URL="https://wallhaven.cc/api/v1/search?${WALLHAVEN_API_KEY}${TAGS}${CATEGORY}${PURITY}atleast=3840x2160&ratios=16x9&sorting=random"
ID="$(curl --silent "$URL" | jq -r '.data[0].id')" ID="$(curl --silent "$URL" | jq -r '.data[0].id')"
IMAGE_META=$(curl --silent "https://wallhaven.cc/api/v1/w/$ID") IMAGE_META=$(curl --silent "https://wallhaven.cc/api/v1/w/$ID")
IMAGE_URL="$(echo "$IMAGE_META" | jq -r '.data.path')" IMAGE_URL="$(echo "$IMAGE_META" | jq -r '.data.path')"