From 8f58616b53c56b2a7638f19ca89b78c21e911392 Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joelgrun@gmail.com>
Date: Mon, 11 Jan 2021 10:45:14 +0000
Subject: [PATCH] make folder if doesnt exist
---
reddit-wallpaper-fetcher | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/reddit-wallpaper-fetcher b/reddit-wallpaper-fetcher
index 310c97e..284cdac 100755
--- a/reddit-wallpaper-fetcher
+++ b/reddit-wallpaper-fetcher
@@ -21,6 +21,8 @@
WALLDIR="$(dirname $(realpath "$0"))"
fi
+[ ! -d "$WALLDIR" ] && mkdir "$WALLDIR"
+[ ! -d "$CONFIR" ] && mkdir "$CONFDIR"
source "$CONFDIR"/reddit-wallpaper-fetcher.conf &>/dev/null
#Loud output for testing a changed config
@@ -53,8 +55,12 @@
#Download image
url=$(echo "$LATEST" | jq ".data.children[-1].data.url" | sed 's/"//g')
+if [ -n "$(echo $url | grep gallery)" ]; then
+ media_id=$(echo "$LATEST" | jq ".data.children[-1].data.gallery_data.items[0].media_id" | sed 's/"//g')
+ url=$(echo "$LATEST" | jq ".data.children[-1].data.media_metadata.$media_id.p[0].u" | sed 's/"//g;s/\?.*//g;s/preview/i/g')
+fi
ext="$(echo "$url" | rev | cut -d'.' -f1 | rev)"
-curl "$LOUD" -o "$WALLDIR/temp.$ext" "$url"
+curl "$url" "$LOUD" --output "$WALLDIR/temp.$ext"
#Save image information
echo "$LATEST" > "$WALLDIR"/json
--
Gitblit v1.10.0