From 1815a0b996d23501e2257e72cc8c6c4e297170e8 Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 30 Jul 2017 17:52:04 -0700 Subject: [PATCH 1/5] --- 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} +' From 075418af219b3d7e759abfbc18088ea415b9eea5 Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 30 Jul 2017 18:08:20 -0700 Subject: [PATCH 2/5] --- following | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/following b/following index c2bea71..d134af6 100644 --- a/following +++ b/following @@ -3,8 +3,20 @@ 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. + +# REQUIREMENTS: +# editing this script. +# downloading a python script. +# python 2 or 3. +# a web browser +# curl +# GNU sort +# GNU awk + +# KNOWN ISSUES: +# stops printing at the first = character per field. +# this should be an easy fix but i'm lazy. +# output is not always sorted by viewer count. # TODO: # fix known issues. @@ -16,9 +28,20 @@ set -e # 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) +cookie="cookie: [fill me in!]" +client_id="client-id: [fill me in!]" + # 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 From 0243eb33dd4a039cce10422caf42db513e9e4bbc Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 30 Jul 2017 19:41:51 -0700 Subject: [PATCH 3/5] --- following | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/following b/following index d134af6..e81299e 100644 --- a/following +++ b/following @@ -8,14 +8,12 @@ set -e # editing this script. # downloading a python script. # python 2 or 3. -# a web browser -# curl -# GNU sort -# GNU awk +# a web browser. +# curl. +# GNU sort. +# GNU awk. # KNOWN ISSUES: -# stops printing at the first = character per field. -# this should be an easy fix but i'm lazy. # output is not always sorted by viewer count. # TODO: @@ -46,19 +44,23 @@ client_id="client-id: [fill me in!]" json2() { # download this from https://github.com/vi/json2/blob/master/json2 # and edit this line accordingly. - python ~/src/json2/json2 "$@" + ~/python3 ~/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'=' ' + -H "$client_id" | json2 | sort -n | awk ' 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} -' +$1~/\/game$/{game=substr($2,2)} +$1~/\/channel\/status$/{status=substr($2,2)} +$1~/\/channel\/name$/{name=substr($2,2)} +$1~/\/viewers$/{ + viewers=substr($2,2); + printf "\x1b[90m%5s\x1b[0m \x1b[97m%-25s\x1b[0m %s\n \x1b[1m%s\x1b[0m\n", + viewers, name, trunc(game, 48), status; +} +' FPAT='(^[^=]+)|(=.*)' From bd2496fa0e02fdca32d11efab15a1af33fe8098c Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 30 Jul 2017 19:42:17 -0700 Subject: [PATCH 4/5] --- following | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/following b/following index e81299e..26cbea9 100644 --- a/following +++ b/following @@ -44,7 +44,7 @@ client_id="client-id: [fill me in!]" json2() { # download this from https://github.com/vi/json2/blob/master/json2 # and edit this line accordingly. - ~/python3 ~/src/json2/json2 "$@" + python ~/src/json2/json2 "$@" } curl -LsS 'https://api.twitch.tv/kraken/streams/followed?limit=100&stream_type=all' \ From d31b7b580eb63a39ef620f3b2abab904ac315f1c Mon Sep 17 00:00:00 2001 From: Connor Date: Sat, 10 Mar 2018 17:30:15 -0800 Subject: [PATCH 5/5] --- following | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/following b/following index 26cbea9..0b6b1ea 100644 --- a/following +++ b/following @@ -13,9 +13,6 @@ set -e # GNU sort. # GNU awk. -# KNOWN ISSUES: -# output is not always sorted by viewer count. - # TODO: # fix known issues. # automatically extract relevant values from a cURL string. @@ -36,31 +33,29 @@ set -e # 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) -cookie="cookie: [fill me in!]" -client_id="client-id: [fill me in!]" +authorization="Authorization: OAuth abcdefghijklmnopqrstuvwxyz1234" -# note: technically, you only need the "persistent" cookie. json2() { # download this from https://github.com/vi/json2/blob/master/json2 # and edit this line accordingly. - python ~/src/json2/json2 "$@" + python3 ~/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 ' -function trunc(s,L) { - e = length(s) > L ? "…" : ""; - return (substr(s, 0, L -(e ? 1 : 0)) e); -} -$1~/\/game$/{game=substr($2,2)} -$1~/\/channel\/status$/{status=substr($2,2)} -$1~/\/channel\/name$/{name=substr($2,2)} -$1~/\/viewers$/{ - viewers=substr($2,2); - printf "\x1b[90m%5s\x1b[0m \x1b[97m%-25s\x1b[0m %s\n \x1b[1m%s\x1b[0m\n", - viewers, name, trunc(game, 48), status; -} -' FPAT='(^[^=]+)|(=.*)' +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='(^[^=]+)|(=.*)'