reddit-wallpaper/reddit-wallpaper

62 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# reddit-wallpaper
# Set wallpaper to the day's top image post in a subreddit
# Copyright © 2021 Keith Irwin www.ki9.us
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Vars
USER_AGENT="reddit-wallpaper https://gitea.gf4.pw/ki9/reddit-wallpaper"
# Parse args
if [ "$#" != "2" ]; then
echo "USAGE: $0 <monitor> <subreddit>"
exit 1
fi
subreddit="$2"
monitor="$1"
# Get top image url
url=$(
curl --silent --user-agent "$USER_AGENT" \
"https://www.reddit.com/r/$subreddit/top/.xml?t=day&limit=1" |\
egrep -o '<content.*>.*</content' |\
egrep -o 'href=.*?' |\
egrep -o 'a href=.*\[link]' |\
awk '{print $NF}' |\
egrep -o 'https?://.*&quot;&gt;' |\
head -c-11
)
if [ "$url" == "" ]; then
echo "Failed to get image!"
exit 3
fi
echo "getting $url"
# Download image
curl --silent --user-agent "$USER_AGENT" "$url" > /tmp/wallpaper
# Set wallpaper
# xfce >4.12.3
xfconf-query \
--channel xfce4-desktop \
--property "$monitor" \
--set /tmp/wallpaper || true
# gnome (untested)
# gsettings set org.gnome.desktop.background picture-uri $url