commit 7ce27f7d37f13956f882c0197dca215047abc45b
parent fe98734b1da80f3298a1270127df798dda5a6fe6
Author: Claudio Alessi <smoppy@gmail.com>
Date: Mon, 21 May 2018 23:36:34 +0200
Add fetchpic
Diffstat:
M | README.md | | | 35 | +++++++++++++++++++++++++++++++++++ |
A | src/fetchpic | | | 51 | +++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -20,6 +20,7 @@ index
* [mkbkp](#mkbkp) - Simple backups.
* [setmon](#setmon) - Switch to HDMI video/audio if any.
* [moin](#moin) - Play a random song from a YouTube playlist.
+* [fetchpic](#fetchpic) - Fetch a random pic from a random blog (of a given list).
iwpick
------
@@ -51,6 +52,10 @@ I'm considering if implement or not a flag to connects to the best possible netw
scrapthumb
----------
Get random images from Tumblr.
+
+Note: currently not working due to the recent Tumblr redirect to the new
+privacy policy, which you need to accept.
+
Some sample usages in ~/.xinitrc:
# Change wallpaper each 5 minutes
@@ -266,3 +271,33 @@ https://www.youtube.com/watch?v=xvIuuKVwY_8&list=RDEMWmz07MSPRGna5rHl5FWPRw&inde
```
Then the ID is: RDEMWmz07MSPRGna5rHl5FWPRw
+
+fetchpic
+--------
+Fetch a random pic from a random blog (of a given list).
+
+This is [scrapthumb](#scrapthumb) rewritten from scratch and better. Now the
+Tumblr API is used so you need an [api key](https://www.tumblr.com/oauth/apps).
+
+In a nutshell:
+
+```
+# scrap="$(APIKEY=Your-Api-Key fetchpic)"
+# uri="$(echo "$scrap" |cut -d'|' -f2)"
+# feh --bg-fill --no-fehbg "$uri"
+```
+
+Put this in your `.xinitrc` to change the wallapaper each 5 minutes and append
+the pic URL and blog name into `/tmp/fetchpic`.
+
+```
+while : ; do
+ scrap="$(APIKEY=Your-Api-Key fetchpic)"
+ uri="$(echo "$scrap" |cut -d' ' -f2)"
+ feh --bg-fill --no-fehbg "$uri"
+ echo "$scrap" >> /tmp/fetchpic
+ sleep 300
+done &
+```
+
+Enjoy.
diff --git a/src/fetchpic b/src/fetchpic
@@ -0,0 +1,51 @@
+#!/bin/bash
+# Fetch a random pic from a random blog (of a given list).
+
+BASEURI="https://api.tumblr.com/v2/blog/"
+GETTER="wget -t1 -qO -"
+
+SOURCES=(
+ "desktopwallpaperproject.tumblr.com"
+ "wallpapermag.tumblr.com"
+ "dsgwallpaper.tumblr.com"
+ "parallax-wallpapers.com"
+ "aerialwallpapers.tumblr.com"
+ "dressupyourtech.tumblr.com"
+ "allfullhdwallpapers.tumblr.com"
+)
+
+die() {
+ echo "$@"
+ exit 1
+}
+
+info() {
+ blog="$1"
+ uri="${BASEURI}${blog}/info/?api_key=${APIKEY}"
+ $GETTER "$uri"
+}
+
+post() {
+ blog="$1"
+ offset="$2"
+ uri="${BASEURI}${blog}/posts/?api_key=${APIKEY}&offset=$offset&limit=1"
+ $GETTER "$uri"
+}
+
+rndblog() {
+ n=${#SOURCES[*]}
+ n="$(echo "${n}-1" | bc)"
+ n="$(shuf -i 0-"$n" -n1)"
+ echo "${SOURCES[$n]}"
+}
+
+main() {
+ [ -z "$APIKEY" ] && die "You need to set the APIKEY variable."
+ blog="$(rndblog)"
+ nposts="$(info "$blog" | grep -oE '"total_posts":([0-9]*)' |cut -d: -f2)"
+ n="$(shuf -i 1-"$nposts" -n1)"
+ pic="$(post "$blog" "$n" |grep -oE '"original_size":{"url":"([^"]*)' |cut -b25-)"
+ echo "$blog $pic"
+}
+
+main "$@"