Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = peripheral.find("monitor")
- --CONFIG--
- streamname="" --This should ALWAYS be lowercase, and within the quotes!
- streamname2="" --If this is empty then it just won't display two streams.
- function="" --This can be either "live" OR "followers". Live tells you if the streamer(s) is (are) live, Followers tells you the last five followers' names, this does NOT support two streams. It also needs a rather tall monitor.
- --CONFIG--
- if not fs.exists('json') then
- write("JSON API not found - Downloading")
- shell.run("pastebin get 4nRg9CHU json")
- end
- function live()
- lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamname).readAll()
- lobj = json.decode(lstr)
- m.setCursorPos(1,1)
- if lobj.stream == nil then
- m.write(streamname)
- m.setCursorPos(1,4)
- m.write(streamname.." is offline.")
- else
- m.write(streamname)
- m.setCursorPos(1,4)
- m.write(streamname.." is live!")
- end
- end
- function live2()
- lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamname2).readAll()
- lobj = json.decode(lstr)
- m.setCursorPos(1,1)
- if lobj.stream == nil then
- m.write(streamname2)
- m.setCursorPos(1,7)
- m.write(streamname2.." is offline.")
- else
- m.write(streamname2)
- m.setCursorPos(1,7)
- m.write(streamname2.." is live!")
- end
- end
- function getFollowers()
- str = http.get("https://api.twitch.tv/kraken/channels/" .. streamname .. "/follows?limit=5").readAll()
- obj = json.decode(str)
- follower = json.encodePretty(obj.follows[1].user.name)
- follower2 = json.encodePretty(obj.follows[2].user.name)
- follower3 = json.encodePretty(obj.follows[3].user.name)
- follower4 = json.encodePretty(obj.follows[4].user.name)
- follower5 = json.encodePretty(obj.follows[5].user.name)
- m.setCursorPos(1,5)
- m.write("Latest Follower: ")
- m.write(follower)
- m.setCursorPos(1,9)
- m.write("Second To Latest Follower: ")
- m.write(follower2)
- m.setCursorPos(1,13)
- m.write("Third To Latest Follower: ")
- m.write(follower3)
- m.setCursorPos(1,16)
- m.write("Fourth To Latest Follower: ")
- m.write(follower4)
- m.setCursorPos(1,20)
- m.write("Fifth To Latest Follower: ")
- m.write(follower5)
- return follows
- end
- while true do
- if function == "live" then
- if streamname2 == nil then
- live()
- else if streamname != nil then
- live()
- live2()
- else
- print("I'M SO CONFUSED!!!")
- end
- else if function == "followers"
- getFollowers()
- end
Advertisement
Add Comment
Please, Sign In to add comment