Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # XKCD Desktop
- # © Christopher Roberts
- # 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/>.
- usage()
- {
- echo "Usage: $0 -r -v -w -u http://xkcd.com/ -d '~/.xkcd'";
- echo " -r : Random"
- echo " -v : Verbose"
- echo " -w : Set as wallpaper using feh (e.g. openbox and pekwm)"
- echo " -u : Set alternative URL"
- echo " -d : Set working directory";
- exit 1;
- }
- # Set default options
- DIR='~/.xkcd'
- URL="http://m.xkcd.com/"
- VERBOSE="0"
- RANDOM="0"
- WALLPAPER="0"
- while getopts "vwru:d:" opt; do
- case "$opt" in
- v) VERBOSE="1";;
- w) WALLPAPER="1";;
- r) RANDOM="1";;
- u) URL="$OPTARG";;
- d) DIR="$OPTARG";;
- [?]) usage;;
- esac
- done
- if [ ! -d "$DIR" ]; then
- echo "Directory $DIR does not exist"
- exit
- fi
- if [ "$RANDOM" = "1" ]; then
- URL="http://dynamic.xkcd.com/random/mobile_comic/"
- fi
- # I'm sure this could probably be halved in length somehow...
- MATCH=`curl -LSs "$URL" | grep -Po "src=\"http:\/\/imgs.xkcd.com\/comics\/.*\.png\" title=\".*?\"" | perl -pe 's/src=\"(http:\/\/imgs.xkcd.com\/comics\/.*\.png)\" title=\"([^"]*)\"/\1%\2/'`
- PNG=`echo "$MATCH" | cut -d "%" -f 1`
- TITLE=`echo "$MATCH" | cut -d "%" -f 2 | perl -pe 's/&#(\d+)\;/’/g' | fold -s`
- if [ "$VERBOSE" = "1" ]; then
- echo "$MATCH"
- echo "$PNG"
- echo "$TITLE"
- fi
- wget -q "$PNG" -O "$DIR/xkcd-src.png" || exit;
- convert "$DIR/xkcd-src.png" -font "$DIR/Humor-Sans.ttf" -gravity Center -background Black -fill White label:"$TITLE" -gravity Center -append "$DIR/xkcd.png"
- if [ "$WALLPAPER" = "1" ];then
- feh --bg-center "$DIR/xkcd.png"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement