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(channelJson: SimpleJSON){
- //channelJson.getInt("id"), channelJson.getString("channel")
- var url = "https://api.twitch.tv/helix/search/channels?query=${channelJson.getString("channel")}" ///live_only=true&
- /*println("aqui...")
- println(url)
- println(channelJson)*/
- val headers = mapOf(
- "client-id" to clientID,
- "Authorization" to "Bearer $accessToken")
- val json = WebClient(url)
- .withHeader(headers)
- //.withHeader("client-id",clientID)
- //.withHeader("Authorization", "Bearer $accessToken")
- .download.asJSON() ?: return
- 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") == "false" || it.getString("display_name") != channelJson.getString("channel")) return@forEach
- ///se tiver online atualiza
- println(it.getString("display_name"))
- println(it.getString("is_live"))
- val posts = mapOf(
- "id" to channelJson.getString("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.asBytes()
- }
- }
- /**
- * 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() ?: return
- json.getJSONList("items").forEach { it ->
- //println(it)
- //busca atualizações, pode retornar 0 caso estiver ainda em live
- /*if (it.getInt("id") > 0 ) {
- checkLive(it)
- }*/
- it.getInt("id").takeIf { it > 0 }?.apply { checkLive(it) }
- }
- ///atualiza o cache somente se retornar algo
- //removi pois já está no cron
- /*if (json.count("items") > 0) {
- WebClient("https://gvapi.gamevicio.com/api/gv/?method=sys.live.cache").withHeader(
- "Cookie",
- "userid=1;username=GameVicio"
- ).download.asBytes()
- }*/
- //println(json)
- //println(total)
- }
- }
Add Comment
Please, Sign In to add comment