Advertisement
ZaxonXP45

wallpaperswide.sh

Oct 17th, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.51 KB | None | 0 0
  1. #!/bin/bash
  2. url=http://wallpaperswide.com
  3. category=forests-desktop-wallpapers
  4. res=1920x1080
  5. crop=25
  6. age=1
  7. ####################################################################################################
  8. loc=/home/user/Pictures/Wallpapers
  9. list=$loc/online_wallpaperswide.txt
  10.  pos=$loc/online_wallpaperswide.last
  11. ldir=$loc/forests
  12. picf=$loc/wallpaper.jpg
  13. chkf=$loc/wallpaper.chk
  14.  
  15. ####################################################################################################
  16. [[ ! -d $loc  ]] && echo "loc directory not existing: $loc" && exit 1
  17. [[ ! -f $list ]] && echo "list file does not exist: $list" && exit 1
  18.  
  19. width=$(( ${res%x*} - $crop ))
  20. height=$(( ${res#*x} - $crop ))
  21.  
  22. ####################################################################################################
  23. if [ "$1" == "-gl" ]; then
  24.  
  25.     pages=$( lynx -listonly -dump -nonumbers -image_links "$url/$category/page/1" | grep page | sort | tail -1)
  26.     last=${pages##*/}
  27.  
  28.     [ -f $list ] && rm $list
  29.  
  30.     count=0
  31.  
  32.     # get list of pages with images
  33.     for (( i = 1; i <= $last ; i++ )); do
  34.  
  35.         echo -ne "\rPage $i of $last ($count)"
  36.  
  37.         for j in $( lynx -listonly -dump -nonumbers -image_links "$url/$category/page/$i" | grep jpg ); do
  38.            
  39.             title=${j##*/}
  40.             title="${title%%t1*}wallpapers.html"
  41.  
  42.             file=$(lynx -listonly -dump -nonumbers -image_links "$url/$title" | grep jpg | grep $res | head -1)
  43.            
  44.             if [ -v file ]; then
  45.                 [[ "$file" != "" ]] && echo $file >> $list && (( count++ ))
  46.             fi
  47.         done
  48.     done
  49.  
  50.     exit 0
  51. fi
  52.  
  53. ####################################################################################################
  54. if [ "$1" == "-l" ];then
  55.     [[ -f $list ]] && cat $list
  56.     exit 0
  57. fi
  58.  
  59. ####################################################################################################
  60. if [ "$1" == "-gi" ]; then
  61.  
  62.     for i in $list; do
  63.         echo "Downloading \"$(basename $i)\""
  64.         wget -q $i
  65.     done
  66.    
  67.     for i in *.jpg; do
  68.         echo "Converting \"$i\""
  69.         convert $i -crop ${width}x${height}+0+0 -resize ${res}^ -gravity center -extent ${res}^ $i
  70.     done
  71.     exit 0
  72. fi
  73.  
  74. ####################################################################################################
  75. background_change() {
  76.     [ -f $pos ] || echo 0 > $pos
  77.     last=$(cat $pos)
  78.     max=$(cat $list | wc -l)
  79.     [ $last = $max ] && next=0 || next=$(( $last + 1 ))
  80.     url=$(cat "$list" | head -n +$next | tail -1)
  81.     echo $next > $pos
  82.  
  83.     wget -q -O "$picf" "$url"
  84.     convert $picf -crop ${width}x${height}+0+0 -resize ${res}^ -gravity center -extent ${res}^ $picf
  85.     hsetroot -full "$picf"
  86.     gsettings set org.mate.screensaver picture-filename $picf
  87. }
  88.  
  89. ####################################################################################################
  90. if [[ "$1" == "-b" ]]; then
  91.     [[ ! -f $chkf ]] && touch $chkf
  92.      ptime=$( stat $picf --printf "%Y" )
  93.     ptimeh=$( stat $picf --printf "%y" )
  94.     ctime=$( stat $chkf --printf "%Y" )
  95.     [[ $ptime -eq $ctime ]] && exit 0
  96.     [[ -f $picf ]] && hsetroot -full $picf || exit 1
  97.     tstamp="${ptimeh:0:4}${ptimeh:5:2}${ptimeh:8:2}${ptimeh:11:2}${ptimeh:14:2}.${ptimeh:17:2}"
  98.     touch -t $tstamp $chkf
  99.     exit 0
  100. fi
  101.  
  102. ####################################################################################################
  103. if [[ "$1" == "-bf" ]]; then
  104.     [[ -f $picf ]] && hsetroot -full $picf || exit 1
  105.     exit 0
  106. fi
  107.  
  108. ####################################################################################################
  109. if [[ "$1" == "-n" ]]; then
  110.     background_change
  111.     exit 0
  112. fi
  113.  
  114. ####################################################################################################
  115. if [[ "$1" == "-c" ]]; then
  116.     if [[ $(( $(/bin/date +%s) - $(stat "$pos" --printf "%Y") )) -ge $(( $age * 3540 )) ]]; then
  117.         background_change
  118.     fi
  119.     exit 0
  120. fi
  121.  
  122. ####################################################################################################
  123. if [[ "$1" == "-r" ]]; then
  124.     [ -v pos ] && echo 0 > $pos
  125.     exit 0
  126. fi
  127.  
  128. echo "$(basename $0) <parameter>"
  129. echo "-gi - get wallpaper images"
  130. echo "-gl - get list of wallpapers"
  131. echo "-l  - display list of URL's to wallpapers"
  132. echo "-n  - download next wallpaper and set it as background"
  133. echo "-c  - change the wallpaper once a day"
  134. echo "-r  - reset position"
  135. echo "-b  - use downloaded wallpaper on background"
  136. echo "-bf - use downloaded wallpaper on background (force)"
  137.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement