Added proper flair search

Added working directory
This commit is contained in:
Benjamyn Love 2021-06-05 13:39:07 +10:00
parent cbc72c9f21
commit 8721513686

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bash
link="https://source.unsplash.com/random/"
dir="$HOME/.local/wallpaper"
# https://www.reddit.com/r/Animewallpaper/search/.json?q=flair_name%3ADesktop&restrict_sr=1
@ -7,8 +8,7 @@ reddit(){
useragent="thevinter"
timeout=60
readarray subreddits < subreddits
readarray subreddits < /home/ben/.git/styli.sh/subreddits
a=${#subreddits[@]}
b=$(($RANDOM % $a))
sub=${subreddits[$b]}
@ -22,16 +22,17 @@ reddit(){
top_time=""
fi
sub="$(echo -e "${sub}" | tr -d '[:space:]')"
if [ ! -z $1 ]; then
if [ ! -z "$1" ] && [ -z "$2" ]; then
sub=$1
fi
# url="https://www.reddit.com/r/$sub/$sort/.json?raw_json=1&t=$top_time"
url="https://www.reddit.com/r/$sub/search/.json?q=flair_name%3ADesktop&restrict_sr=1"
# echo $url
# exit
if [[ $2 -eq "flair" ]]
then
url="https://www.reddit.com/r/$sub/search/.json?q=flair_name%3A$1&restrict_sr=1"
else
url="https://www.reddit.com/r/$sub/$sort/.json?raw_json=1&t=$top_time"
fi
# url="https://www.reddit.com/r/$sub/search/.json?q=flair_name%3ADesktop&restrict_sr=1"
content=`wget -T $timeout -U "$useragent" -q -O - $url`
# echo $content
# exit
# urls=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")?) | .data.preview.images[0].source.url')
urls=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")?) | .data.url')
names=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")?) | .data.title')
@ -47,11 +48,12 @@ reddit(){
target_id=${arrIDS[$idx]}
ext=`echo -n "${target_url##*.}"|cut -d '?' -f 1`
newname=`echo $target_name | sed "s/^\///;s/\// /g"`_"$subreddit"_$target_id.$ext
wget -T $timeout -U "$useragent" --no-check-certificate -q -P down -O "wallpaper.jpg" $target_url &>/dev/null
wget -T $timeout -U "$useragent" --no-check-certificate -q -P down -O "$dir/wallpaper.jpg" $target_url &>/dev/null
}
usage(){
echo "Usage: styli.sh [-s | --search <string>]
[-f | --flair <flair>]
[-h | --height <hight>]
[-w | --width <width>]
[-b | --fehbg <feh bg opt>]
@ -61,8 +63,14 @@ usage(){
[-p | --termcolor]"
exit 2
}
if [ ! -d "$dir" ]
then
mkdir -p "$dir"
fi
pywal=0
PARSED_ARGUMENTS=$(getopt -a -n $0 -o h:w:s:l:b:r:c:p --long search:,hight:,width:,fehbg:,fehopt:,subreddit:,termcolor -- "$@")
PARSED_ARGUMENTS=$(getopt -a -n $0 -o h:w:s:l:b:r:c:p:f --long flair:,search:,hight:,width:,fehbg:,fehopt:,subreddit:,termcolor -- "$@")
VALID_ARGUMENTS=$?
if [ "$VALID_ARGUMENTS" != "0" ]; then
usage
@ -72,6 +80,7 @@ do
case "${1}" in
-b | --fehbg) bgtype=${2} ; shift 2 ;;
-s | --search) search=${2} ; shift 2 ;;
-f | --flair) flair=${2} ; shift 2 ;;
-h | --height) height=${2} ; shift 2 ;;
-w | --width) width=${2} ; shift 2 ;;
-l | --link) link=${2} ; shift 2 ;;
@ -107,12 +116,17 @@ if [ ! -z $custom ]; then
fi
if [ $link = "reddit" ] || [ ! -z $sub ]
then
if [ ! -z $flair ]
then
reddit "$flair" "flair"
else
reddit "$sub"
feh+=(wallpaper.jpg)
fi
feh+=("$dir/wallpaper.jpg")
"${feh[@]}"
if [ $pywal -eq 1 ]; then
wal -c
wal -i wallpaper.jpg -n
wal -i "$dir/wallpaper.jpg" -n
fi
else
if [ ! -z $height ] || [ ! -z $width ]; then
@ -124,12 +138,12 @@ else
then
link="${link}/?${search}"
fi
wget -q -O wallpaper $link
feh+=(wallpaper)
wget -q -O "$dir/wallpaper" $link
feh+=("$dir/wallpaper")
"${feh[@]}"
if [ $pywal -eq 1 ]; then
wal -c
wal -i wallpaper -n
wal -i "$dir/wallpaper" -n
fi
fi