twitch.sh - twitch-go - twitch.tv web application in Go
 (HTM) git clone git://git.codemadness.org/twitch-go
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       twitch.sh (849B)
       ---
            1 #!/bin/sh
            2 # Twitch.tv playlist grab script.
            3 # License: WTFPL
            4 # Author:  Hiltjo Posthuma <hiltjo@codemadness.org>
            5 # NOTE:    channel name is very case-sensitive ;_;
            6 
            7 err() {
            8         printf '%s\n' "$1" >&2
            9         exit 1
           10 }
           11 
           12 [ "$1" = "" ] && err "Usage: $0 <channel>"
           13 clientid="client_id_here"
           14 channel="$1"
           15 tokenurl="https://api.twitch.tv/api/channels/${channel}/access_token"
           16 tokendata=$(curl -s -H "Client-ID: ${clientid}" "$tokenurl")
           17 token=$(printf '%s' "${tokendata}" | sed -E -e 's@.*"token":"(.*)","sig".*@\1@g' -e 's@\\"@"@g')
           18 sig=$(printf '%s' "${tokendata}" | sed -E 's@.*"sig":"([^"]*)".*@\1@g')
           19 
           20 if test x"$token" != x"" && test x"$sig" != x""; then
           21         curl -G \
           22                 "http://usher.justin.tv/api/channel/hls/${channel}.m3u8" \
           23                 --data-urlencode "token=${token}" \
           24                 --data-urlencode "sig=${sig}"
           25 else
           26         err 'no token found: channel possibly gone offline'
           27 fi
           28