Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program made by MCTVMessy
- -- Youtube, Twitch, Twitter - /MCTVMessy
- -- StreamID - Change to needed channel
- streamid = "OfficialMCTVmessy"
- -- Set the Y line on the monitor
- line_streamer = 1
- line_followers = 3
- line_follower = 4
- line_viewers = 5
- -- SleepTime to set how often to grab new info from
- -- the api, if it is too fast, then twitch will
- -- flag you for spam, and stop sending data!
- SleepTime = 60
- -- Check to see if the JSON api exists, download it
- if not fs.exists('json') then
- print("JSON API not found - Downloading...")
- shell.run("pastebin get 4nRg9CHU json")
- end
- os.loadAPI("json")
- local m = peripheral.find("monitor")
- m.setTextColor(colors.white)
- m.setTextScale(1)
- function getFollowers()
- str = http.get("https://api.twitch.tv/kraken/channels" .. streamid .. "/followers?limit=1").readAll()
- obj = json.decode(str)
- follows = json.encodePretty(obj._total)
- follower = json.encodePretty(obj.follows[1].user.name)
- follower = follower:gsub('"', '')
- return follows, follower
- end
- function getViewerCount()
- str = http.get("https://api.twitch.tv/kraken/streams/" .. streamid).readAll()
- obj = json.decode(str)
- if obj.stream == nil then
- return nil
- else
- return json.encodePretty(obj.stream.viewers)
- end
- end
- while true do
- local status, live = pcall(getViewerCount)
- if status then
- m.setCursorPos(1,line_streamer)
- if live == nil then
- m.setBackgroundColor(colors.white)
- m.clear()
- m.write(streamid)
- m.setCursorPos(1,line_viewers)
- m.write("Live Viewers: Offline")
- else
- m.setBackgroundColor(colors.red)
- m.clear()
- m.write(streamid)
- m.setCursorPos(1,line_viewers)
- m.write("Live Viewers: " .. live)
- end
- else
- m.setBackgroundColor(colors.orange)
- m.clear()
- m.write(streamid)
- m.setCursorPos(1,line_viewers)
- end
- local status, followers, follower = pcall(getFollowers)
- if status then
- m.setCursorPos(1,line_followers)
- m.write("Twitch Followers: " .. followers)
- m.setCursorPos(1,line_follower)
- m.write("Last Follower: " .. follower)
- else
- m.setCursorPos(1,line_followers)
- m.write("Twitch Followers: ERROR")
- m.setCursorPos(1,line_follower)
- m.write("Last Follower: ERROR")
- end
- sleep(SleepTime)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement