This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kd8lvt's profile picture

Kd's Twitch Interface-API

Started by kd8lvt, 06 November 2015 - 11:51 PM
kd8lvt #1
Posted 07 November 2015 - 12:51 AM
Have you ever wanted to know when a certain streamer is live, but you don't want to leave the game? Perhaps you want a quick easy way to see your latest follower? Maybe you want to see your viewer or follower count? You probably want a computerized solution to this problem, yeah? Want to make it easier on yourself with an API? Well, here is what you have been looking for all along!

Kd's Twitch Interface-API

The basic gist of how this works: It uses the JSON api (found here though it auto-downloads) by the talented ElvishJerricco
It asks the twitch API servers for a streamer's stream (or follows) element you specify (see usage below) and then spits out information regarding the function you choose. I highly recommend having a second or so sleep every four or so times you 'ping' Twitch, otherwise you may get temporarily banned from the Twitch api ;)/>

USAGE:

os.loadAPI("twitchapi")
twitchapi.live("wolftaz",colors.green,colors.red) -- argumets: streamer name, live color, NOT live color
OR…

os.loadAPI("twitchapi")
if twitchapi.checkLive("choobtastic") then
  print("Live!")
else
  print("Not live!")
end
OR…

os.loadAPI("twitchapi")
print(twitchapi.lastFollower("rebelofroses")
OR…

os.loadAPI("twitchapi")
print(twitchapi.followerCount("EthanRay10"))
OR…

os.loadAPI("twitchapi")
print(twitchapi.viewerCount("kd8lvt"))
OR…

os.loadAPI("twitchapi")
print(twitchapi.viewCount("leavaris")) --This only works when the stream is LIVE! Additionally, View count it DIFFERENT from current VIEWERS! This is how many times the stream page has been loaded!
If you want, here is the code so you can suggest improvements:
SpoilerLook at the pastebin, its got the most up to date version!
DOWNLOADS:

API: pastebin get vh4Jd1B6 twitchapi
EXAMPLE: pastebin get BkR9un49 example

NEW! My friend, Funniray, has slightly edited the API for beam.pro use!
pastebin get wbPC0Zv7 beamapi
Edited on 04 January 2016 - 02:13 PM
Creator #2
Posted 07 November 2015 - 08:05 AM
Maybe you can add an option telling the API to check NOW which would allow you to not flood the twitch servers and to check whenever YOU want.
kd8lvt #3
Posted 07 November 2015 - 12:03 PM
I'm not sure I understand what you mean, it only checks when you call the function "live" which is checking now - and I'm not sure what you mean by "check whenever YOU want"
==EDIT==
OH, it can do three or four 'pings' in a row, but once you get to five it gets a bit dicey. Maybe I should word that differently.
Edited on 07 November 2015 - 11:05 AM