Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- url=http://wallpaperswide.com
- category=forests-desktop-wallpapers
- res=1920x1080
- crop=25
- age=1
- ####################################################################################################
- loc=/home/user/Pictures/Wallpapers
- list=$loc/online_wallpaperswide.txt
- pos=$loc/online_wallpaperswide.last
- ldir=$loc/forests
- picf=$loc/wallpaper.jpg
- chkf=$loc/wallpaper.chk
- ####################################################################################################
- [[ ! -d $loc ]] && echo "loc directory not existing: $loc" && exit 1
- [[ ! -f $list ]] && echo "list file does not exist: $list" && exit 1
- width=$(( ${res%x*} - $crop ))
- height=$(( ${res#*x} - $crop ))
- ####################################################################################################
- if [ "$1" == "-gl" ]; then
- pages=$( lynx -listonly -dump -nonumbers -image_links "$url/$category/page/1" | grep page | sort | tail -1)
- last=${pages##*/}
- [ -f $list ] && rm $list
- count=0
- # get list of pages with images
- for (( i = 1; i <= $last ; i++ )); do
- echo -ne "\rPage $i of $last ($count)"
- for j in $( lynx -listonly -dump -nonumbers -image_links "$url/$category/page/$i" | grep jpg ); do
- title=${j##*/}
- title="${title%%t1*}wallpapers.html"
- file=$(lynx -listonly -dump -nonumbers -image_links "$url/$title" | grep jpg | grep $res | head -1)
- if [ -v file ]; then
- [[ "$file" != "" ]] && echo $file >> $list && (( count++ ))
- fi
- done
- done
- exit 0
- fi
- ####################################################################################################
- if [ "$1" == "-l" ];then
- [[ -f $list ]] && cat $list
- exit 0
- fi
- ####################################################################################################
- if [ "$1" == "-gi" ]; then
- for i in $list; do
- echo "Downloading \"$(basename $i)\""
- wget -q $i
- done
- for i in *.jpg; do
- echo "Converting \"$i\""
- convert $i -crop ${width}x${height}+0+0 -resize ${res}^ -gravity center -extent ${res}^ $i
- done
- exit 0
- fi
- ####################################################################################################
- background_change() {
- [ -f $pos ] || echo 0 > $pos
- last=$(cat $pos)
- max=$(cat $list | wc -l)
- [ $last = $max ] && next=0 || next=$(( $last + 1 ))
- url=$(cat "$list" | head -n +$next | tail -1)
- echo $next > $pos
- wget -q -O "$picf" "$url"
- convert $picf -crop ${width}x${height}+0+0 -resize ${res}^ -gravity center -extent ${res}^ $picf
- hsetroot -full "$picf"
- gsettings set org.mate.screensaver picture-filename $picf
- }
- ####################################################################################################
- if [[ "$1" == "-b" ]]; then
- [[ ! -f $chkf ]] && touch $chkf
- ptime=$( stat $picf --printf "%Y" )
- ptimeh=$( stat $picf --printf "%y" )
- ctime=$( stat $chkf --printf "%Y" )
- [[ $ptime -eq $ctime ]] && exit 0
- [[ -f $picf ]] && hsetroot -full $picf || exit 1
- tstamp="${ptimeh:0:4}${ptimeh:5:2}${ptimeh:8:2}${ptimeh:11:2}${ptimeh:14:2}.${ptimeh:17:2}"
- touch -t $tstamp $chkf
- exit 0
- fi
- ####################################################################################################
- if [[ "$1" == "-bf" ]]; then
- [[ -f $picf ]] && hsetroot -full $picf || exit 1
- exit 0
- fi
- ####################################################################################################
- if [[ "$1" == "-n" ]]; then
- background_change
- exit 0
- fi
- ####################################################################################################
- if [[ "$1" == "-c" ]]; then
- if [[ $(( $(/bin/date +%s) - $(stat "$pos" --printf "%Y") )) -ge $(( $age * 3540 )) ]]; then
- background_change
- fi
- exit 0
- fi
- ####################################################################################################
- if [[ "$1" == "-r" ]]; then
- [ -v pos ] && echo 0 > $pos
- exit 0
- fi
- echo "$(basename $0) <parameter>"
- echo "-gi - get wallpaper images"
- echo "-gl - get list of wallpapers"
- echo "-l - display list of URL's to wallpapers"
- echo "-n - download next wallpaper and set it as background"
- echo "-c - change the wallpaper once a day"
- echo "-r - reset position"
- echo "-b - use downloaded wallpaper on background"
- echo "-bf - use downloaded wallpaper on background (force)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement