#!/usr/bin/env bash set -e # super quickly hacked together script # for listing your twitch following from the command-line. # REQUIREMENTS: # editing this script. # downloading a python script. # python 2 or 3. # a web browser. # curl. # GNU sort. # GNU awk. # 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. # 1. open a new tab in Chromium or Firefox; these instructions apply to either. # 2. open the web inspector (ctrl+shift+I) and click on the network tab. # 3. go to https://www.twitch.tv/directory/following/live # make sure this is with the network tab already open! # if it isn't, open it up and just refresh the page. # 4. type "followed" in the filter of the network tab. # 5. right click on the first result and click copy as cURL. # in Chromium, it's in a submenu as "copy as cURL (bash)" # 6. paste into a text editor and extract the following header values: # (each header is specified by a -H flag) authorization="Authorization: OAuth abcdefghijklmnopqrstuvwxyz1234" json2() { # download this from https://github.com/vi/json2/blob/master/json2 # and edit this line accordingly. python3 ~/src/json2/json2 "$@" } curl -LsS 'https://gql.twitch.tv/gql' \ -H "$authorization" \ --data-binary '[{"variables":{"limit":100},"extensions":{},"operationName":"FollowingLive_CurrentUser","query":"query FollowingLive_CurrentUser($limit: Int, $cursor: Cursor) {\n currentUser {\n follows {\n totalCount\n }\n followedLiveUsers(first: $limit, after: $cursor) {\n edges {\n node {\n login\n displayName\n stream {\n game {\n name\n }\n viewersCount\n title\n type\n }\n }\n }\n pageInfo {\n hasNextPage\n }\n }\n }\n}\n"}]' \ | json2 | tr -d '\r' | awk ' function trunc(s,L) { e = length(s) > L ? "…" : ""; return (substr(s, 0, L -(e ? 1 : 0)) e); } $1~/\/stream\/game\/name$/{game=substr($2,2)} $1~/\/stream\/title$/{title=substr($2,2)} $1~/\/login$/{name=substr($2,2)} $1~/\/viewersCount$/{viewers=substr($2,2)} $1~/\/stream\/type$/{ printf "\x1b[90m%5s\x1b[0m \x1b[97m%-25s\x1b[0m %s\n \x1b[36m%s\x1b[0m\n", viewers, name, trunc(game, 48), title; } ' FPAT='(^[^=]+)|(=.*)'