Advertisement
Guest User

beamapi

a guest
Jan 3rd, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. --=========--
  2. --Changelog--
  3. --=========--
  4. --Version 1.1.0
  5. --1. Fixed live() crash bug!
  6. --2. Made file smaller, to save on disk space using init()!
  7. --=========--
  8. --Changelog--
  9. --=========--
  10. function getStreamId(streamer)
  11.   isjsoninstalled()
  12.   str = http.get("https://beam.pro/api/v1/channels/"..streamer).readAll()
  13.   obj = json.decode(str)
  14.   return obj["id"]
  15. end
  16. function getChannel(streamname)
  17.   streamid = getStreamId(streamname)
  18.   str = http.get("https://beam.pro/api/v1/channels/"..streamid).readAll()
  19.   obj = json.decode(str)
  20.   return obj
  21. end
  22. function getFollow(streamname)
  23.   streamid = setStreamId(streamname)
  24.   str = http.get("https://beam.pro/api/v1/channels/"..streamid.."/follow").readAll()
  25.   obj = json.decode(str)
  26.   return obj
  27. end
  28. function isjsoninstalled()
  29.   if fs.exists("json") then
  30.     return true
  31.   else
  32.     print("JSON API Not found! Downloading...")
  33.     resp = http.get("http://pastebin.com/raw.php?i=4nRg9CHU")
  34.     if resp then
  35.       handler = io.open("json","w")
  36.       handler:write(resp.readAll())
  37.       handler:close()
  38.     end
  39.     print("Finished downloading JSON API!")
  40.     return true
  41.   end
  42. end    
  43. function checkLive(streamid)
  44. stream = getChannel(streamid)
  45.   if stream["online"] == true then
  46.     return true
  47.   else
  48.     return false
  49.   end
  50. end
  51. function lastFollower(streamid)
  52.   follow = getFollow(streamid)
  53.   return lastfollow["username"]
  54. end
  55. function followerCount(streamid)
  56.   stream = getChannel(streamid)
  57.   follows = stream["numFollowers"]
  58.   return follows
  59. end
  60. function viewerCount(streamid)
  61.   stream = getChannel(streamid)
  62.   return stream["viewersCurrent"]
  63. end
  64. function viewCount(streamid)
  65.   stream = getChannel(streamid)
  66.   return stream["viewersTotal"]
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement