Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import core.io.SimpleJSON
- import core.net.WebClient
- class Twitch {
- val clientID = "3t6ct5oofvv82si9jkhixvsbyh204b"
- val clientSecret = "2ukqmk576idjqbbtm510v4iozcch1p"
- val redirectURL = "https://painel3.gamevicio.com/twitch.php"
- val accessToken = "j8nd2n7hlhhcf6p2zsrsyt75rquvp2" ///nao sei quanto tempos erá valido
- /**
- * retorna o tokken
- */
- fun getTokken(){
- println(WebClient("https://id.twitch.tv/oauth2/authorize?client_id=$clientID&redirect_uri=$redirectURL&response_type=token&scope=viewing_activity_read").
- download.asString())
- ////irá retornar uma URL de redirecionamento para enviar um SMS
- /// abra e logue-se, confirme o codigo do SMS e peque o tokken
- }
- /**
- * verifica se esta online
- */
- fun checkLive(id:Int,Channel:String){
- var url = "https://api.twitch.tv/helix/search/channels?query=$Channel" ///live_only=true&
- val json = WebClient(url)
- .withHeader("client-id",clientID)
- .withHeader("Authorization","Bearer $accessToken")
- .download.asJSON()
- if (json != null) {
- json.getJSONList("data").forEach {
- //println(it)
- ////so atualiza se estiver em live, e o channel for igual ao display_name
- if (it.getString("is_live") == "true" && it.getString("display_name") == Channel){
- ///se tiver online atualiza
- println(it.getString("display_name"))
- println(it.getString("is_live"))
- val posts = mapOf(
- "id" to id,
- "content" to it.getString("title")
- )
- WebClient("https://painel3.gamevicio.com/control.php?area=live.update")
- .withHeader("Cookie","userid=1;username=GameVicio")
- .withPost(posts)
- .download.asJSON()
- }
- }
- }
- }
- /**
- * baixa a lista a ser verificada
- */
- fun getList(){
- var url = "https://painel3.gamevicio.com/control.php?area=live.list" ///live_only=true&
- val json = WebClient(url).withHeader("Cookie","userid=1;username=GameVicio").download.asJSON()
- if (json != null) {
- val total = json?.count("items")
- json.getJSONList("items").forEach {
- //println(it)
- //busca atualizações, pode retornar 0 caso estiver ainda em live
- if (it.getInt("id") > 0 ) {
- checkLive(it.getInt("id"), it.getString("channel"))
- }
- }
- ///atualiza o cache somente se retornar algo
- if (json?.count("items") > 0) {
- WebClient("https://gvapi.gamevicio.com/api/gv/?method=sys.live.cache").withHeader(
- "Cookie",
- "userid=1;username=GameVicio"
- ).download.asJSON()
- }
- }
- //println(json)
- //println(total)
- }
- }
Add Comment
Please, Sign In to add comment