@ -1,42 +1,29 @@
#!/usr/bin/env bash
### _ _ _ _
### __ _ ___ | |_| |__ | | ___| |_ _ _
### / _` |/ _ \| __| '_ \| |/ _ \ __| | | |
###| (_| | (_) | |_| |_) | | __/ |_| |_| |
### \__, |\___/ \__|_.__/|_|\___|\__|\__,_|
### |___/
### https://www.youtube.com/user/gotbletu
### https://twitter.com/gotbletu
### https://github.com/gotbletu
### gotbletu@gmail.com
###
### Author : gotbletu
### Name : dl_wallhaven_wallpapers.sh
### Version : 0.2
### Date : 20190811
### Description : A script to download random wallpaper and delete old wallpaper at the sametime (wallhaven.cc)
### Depends On : bash coreutils grep findutils lynx wget
### Video Demo : https://www.youtube.com/watch?v=cDtVEXjiKTw
### Release Notes : 20190811 -- v0.2 minor fixes to get it working again
### 20170121 -- v0.1 it has begun
# author: gotbletu (@youtube|github|odysee)
# https://www.youtube.com/user/gotbletu
# desc: a script to download random wallpaper and delete old wallpaper at the sametime (wallhaven.cc)
# demo: https://www.youtube.com/watch?v=cDtVEXjiKTw
# depend: curl grep sed findutils coreutils wget
# Variable (you can change any of these to your liking)
real_wall_ dir= ~/Pictures/Wallpapers
temp _wall_ dir= /tmp/wallpaper_wallhaven
expire_ wall_ date= 30
savedir = ~/Pictures/Wallpapers
tempdir = /tmp/wallpaper_wallhaven
expire_date = 30
# create folders
mkdir -p $real_wall_dir
mkdir -p $temp_wall_dir
mkdir -p $savedir
mkdir -p $tempdir
cd $tempdir || exit
# change the url if you need different resolutions
curl -f -L 'https://wallhaven.cc/search?categories=111&purity=100&resolutions=1920x1080&sorting=random&order=desc&ai_art_filter=1' | grep -Eo "https?://\S+?\"" | grep small | cut -d '"' -f1 | sed -e 's@//th@//w@g' -e 's/small/full/g' -e 's@/@/wallhaven-@5' | while read -r link ; do wget --timestamping " $link " || wget --timestamping " ${ link //.jpg/.png } " ; done
cd $temp_wall_dir
# get links of images and download it
get_random_url = $( lynx -listonly -nonumbers -dump "https://wallhaven.cc/random" | grep '/w/' )
get_images_url = $( echo " $get_random_url " | while read line; do lynx -source " $line " | grep -Po '<img id="wallpaper" src="\K[^"]+' ; done )
dl_images = $( echo " $get_images_url " | while read line; do wget -N " $line " ; done )
# # get links of images and download it
# get_random_url=$(lynx -listonly -nonumbers -dump "https://wallhaven.cc/random" | grep '/w/' )
# get_images_url=$(echo "$get_random_url" | while read -r line; do lynx -source "$line" | grep -Po '<img id="wallpaper" src="\K[^"]+' ; done )
# echo "$get_images_url" | while read -r line; do wget -N "$line" ; done
# delete any file under 200k in size (to avoid shitty thumnbails or crap quality)
find . -type f -iname "*.jp*g" -size -200k -exec rm { } \;
@ -49,10 +36,10 @@ find . -type f -iname "*.png" -exec touch -m {} \;
# now that everything is cleaned and filter
# send the downloaded images to the wallpaper folder
find . -type f -iname "*.jp*g" -exec mv { } $ real_wall_ dir \;
find . -type f -iname "*.png" -exec mv { } $ real_wall_ dir \;
find . -type f -iname "*.jp*g" -exec mv { } $ save dir \;
find . -type f -iname "*.png" -exec mv { } $ save dir \;
# delete wallpaper image older then X days and remove temp folder
rm -rf $temp _wall_ dir
find $ real_wall_dir -mtime +$expire_wall _date -exec rm { } \;
rm -rf $temp dir
find $ savedir -mtime +$expire _date -exec rm { } \;