Added proper flair search
Added working directory
This commit is contained in:
parent
cbc72c9f21
commit
8721513686
48
styli.sh
48
styli.sh
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
link="https://source.unsplash.com/random/"
|
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
|
# https://www.reddit.com/r/Animewallpaper/search/.json?q=flair_name%3ADesktop&restrict_sr=1
|
||||||
|
|
||||||
@ -7,8 +8,7 @@ reddit(){
|
|||||||
useragent="thevinter"
|
useragent="thevinter"
|
||||||
timeout=60
|
timeout=60
|
||||||
|
|
||||||
readarray subreddits < subreddits
|
readarray subreddits < /home/ben/.git/styli.sh/subreddits
|
||||||
|
|
||||||
a=${#subreddits[@]}
|
a=${#subreddits[@]}
|
||||||
b=$(($RANDOM % $a))
|
b=$(($RANDOM % $a))
|
||||||
sub=${subreddits[$b]}
|
sub=${subreddits[$b]}
|
||||||
@ -22,16 +22,17 @@ reddit(){
|
|||||||
top_time=""
|
top_time=""
|
||||||
fi
|
fi
|
||||||
sub="$(echo -e "${sub}" | tr -d '[:space:]')"
|
sub="$(echo -e "${sub}" | tr -d '[:space:]')"
|
||||||
if [ ! -z $1 ]; then
|
if [ ! -z "$1" ] && [ -z "$2" ]; then
|
||||||
sub=$1
|
sub=$1
|
||||||
fi
|
fi
|
||||||
# url="https://www.reddit.com/r/$sub/$sort/.json?raw_json=1&t=$top_time"
|
if [[ $2 -eq "flair" ]]
|
||||||
url="https://www.reddit.com/r/$sub/search/.json?q=flair_name%3ADesktop&restrict_sr=1"
|
then
|
||||||
# echo $url
|
url="https://www.reddit.com/r/$sub/search/.json?q=flair_name%3A$1&restrict_sr=1"
|
||||||
# exit
|
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`
|
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.preview.images[0].source.url')
|
||||||
urls=$(echo -n "$content"| jq -r '.data.children[]|select(.data.post_hint|test("image")?) | .data.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')
|
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]}
|
target_id=${arrIDS[$idx]}
|
||||||
ext=`echo -n "${target_url##*.}"|cut -d '?' -f 1`
|
ext=`echo -n "${target_url##*.}"|cut -d '?' -f 1`
|
||||||
newname=`echo $target_name | sed "s/^\///;s/\// /g"`_"$subreddit"_$target_id.$ext
|
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(){
|
usage(){
|
||||||
echo "Usage: styli.sh [-s | --search <string>]
|
echo "Usage: styli.sh [-s | --search <string>]
|
||||||
|
[-f | --flair <flair>]
|
||||||
[-h | --height <hight>]
|
[-h | --height <hight>]
|
||||||
[-w | --width <width>]
|
[-w | --width <width>]
|
||||||
[-b | --fehbg <feh bg opt>]
|
[-b | --fehbg <feh bg opt>]
|
||||||
@ -61,8 +63,14 @@ usage(){
|
|||||||
[-p | --termcolor]"
|
[-p | --termcolor]"
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [ ! -d "$dir" ]
|
||||||
|
then
|
||||||
|
mkdir -p "$dir"
|
||||||
|
fi
|
||||||
|
|
||||||
pywal=0
|
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=$?
|
VALID_ARGUMENTS=$?
|
||||||
if [ "$VALID_ARGUMENTS" != "0" ]; then
|
if [ "$VALID_ARGUMENTS" != "0" ]; then
|
||||||
usage
|
usage
|
||||||
@ -72,6 +80,7 @@ do
|
|||||||
case "${1}" in
|
case "${1}" in
|
||||||
-b | --fehbg) bgtype=${2} ; shift 2 ;;
|
-b | --fehbg) bgtype=${2} ; shift 2 ;;
|
||||||
-s | --search) search=${2} ; shift 2 ;;
|
-s | --search) search=${2} ; shift 2 ;;
|
||||||
|
-f | --flair) flair=${2} ; shift 2 ;;
|
||||||
-h | --height) height=${2} ; shift 2 ;;
|
-h | --height) height=${2} ; shift 2 ;;
|
||||||
-w | --width) width=${2} ; shift 2 ;;
|
-w | --width) width=${2} ; shift 2 ;;
|
||||||
-l | --link) link=${2} ; shift 2 ;;
|
-l | --link) link=${2} ; shift 2 ;;
|
||||||
@ -107,12 +116,17 @@ if [ ! -z $custom ]; then
|
|||||||
fi
|
fi
|
||||||
if [ $link = "reddit" ] || [ ! -z $sub ]
|
if [ $link = "reddit" ] || [ ! -z $sub ]
|
||||||
then
|
then
|
||||||
reddit "$sub"
|
if [ ! -z $flair ]
|
||||||
feh+=(wallpaper.jpg)
|
then
|
||||||
|
reddit "$flair" "flair"
|
||||||
|
else
|
||||||
|
reddit "$sub"
|
||||||
|
fi
|
||||||
|
feh+=("$dir/wallpaper.jpg")
|
||||||
"${feh[@]}"
|
"${feh[@]}"
|
||||||
if [ $pywal -eq 1 ]; then
|
if [ $pywal -eq 1 ]; then
|
||||||
wal -c
|
wal -c
|
||||||
wal -i wallpaper.jpg -n
|
wal -i "$dir/wallpaper.jpg" -n
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ ! -z $height ] || [ ! -z $width ]; then
|
if [ ! -z $height ] || [ ! -z $width ]; then
|
||||||
@ -124,12 +138,12 @@ else
|
|||||||
then
|
then
|
||||||
link="${link}/?${search}"
|
link="${link}/?${search}"
|
||||||
fi
|
fi
|
||||||
wget -q -O wallpaper $link
|
wget -q -O "$dir/wallpaper" $link
|
||||||
feh+=(wallpaper)
|
feh+=("$dir/wallpaper")
|
||||||
"${feh[@]}"
|
"${feh[@]}"
|
||||||
if [ $pywal -eq 1 ]; then
|
if [ $pywal -eq 1 ]; then
|
||||||
wal -c
|
wal -c
|
||||||
wal -i wallpaper -n
|
wal -i "$dir/wallpaper" -n
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user