imgur_album.sh - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
imgur_album.sh (824B)
---
1 #!/bin/sh
2 # Imgur album viewer/ripper
3 # Dependencies: json2tsv, awk, curl, POSIX sh.
4 # Optional dmenu_urls_plumb script: https://git.codemadness.org/randomcrap/
5
6 if test -z "$1"; then
7 echo "$0 <albumid>" >&2
8 exit 1
9 fi
10
11 albumid="$1"
12 clientid="546c25a59c58ad7"
13 url="https://api.imgur.com/post/v1/albums/${albumid}?client_id=${clientid}&include=media%2Cadconfig%2Caccount"
14
15 # imgur incorrectly sends compressed data even if it is not requested, so make
16 # cur l request it so it doesn't report it as an error.
17 curl -s --compressed -H 'User-Agent:' "$url" | \
18 json2tsv | \
19 awk -F '\t' '
20 function show(o) {
21 if (length(o["url"]) == 0)
22 return;
23 printf("%4d. %-50.50s %s\n", n, o["name"], o["url"]);
24 }
25 $1 == ".media[]" {
26 show(o);
27 n++;
28 delete o;
29 }
30 $1 ~ ".media[].[a-zA-Z0-9_]*$" {
31 o[substr($1, 10)] = $3;
32 } END {
33 show();
34 }'