From 1815a0b996d23501e2257e72cc8c6c4e297170e8 Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 30 Jul 2017 17:52:04 -0700 Subject: [PATCH] --- following | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 following diff --git a/following b/following new file mode 100644 index 0000000..c2bea71 --- /dev/null +++ b/following @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -e + +# super quickly hacked together script +# for listing your twitch following from the command-line. +# KNOWN ISSUES: stops printing at the first = character per field. +# this should be an easy fix but i'm lazy. + +# TODO: +# fix known issues. +# automatically extract relevant values from a cURL string. +# add toggle for colors. +# optional CSV output. +# automatically download json2? +# rewrite in python? + +# fill these in with values extracted from your browser's +# "copy as cURL" feature. +# note: technically, you only need the "persistent" cookie. +cookie="cookie: [stuff goes here]" +client_id="client-id: [stuff goes here]" + +json2() { + # download this from https://github.com/vi/json2/blob/master/json2 + # and edit this line accordingly. + python ~/src/json2/json2 "$@" +} + +curl -LsS 'https://api.twitch.tv/kraken/streams/followed?limit=100&stream_type=all' \ + -H 'accept: application/vnd.twitchtv.v5+json' \ + -H "$cookie" \ + -H "$client_id" | json2 | sort -n | awk -F'=' ' +function trunc(s,L) { + e = length(s) > L ? "…" : ""; + return (substr(s, 0, L -(e ? 1 : 0)) e); +} +$1~/\/game$/{game=$2} +$1~/\/channel\/status$/{status=$2} +$1~/\/channel\/name$/{name=$2} +$1~/\/viewers$/{printf "\x1b[90m%5s\x1b[0m \x1b[97m%-25s\x1b[0m %s\n \x1b[1m%s\x1b[0m\n",$2,name,trunc(game,48),status} +'