28.05.2017

Twitch Sockread Script für mIRC

Es geht wieder!

Dieses mIRC MSL Script ruft bei jeder Twitch Channel URL (https://twitch.tv/lightningsoul bspw.), die in einem IRC Kanal gepostet wird die Infos (Spiel, Zuschauer und Livestatus) ab und gibt diese im entsprechenden IRC Channel aus.

;Twitch Info 2.0
;Created with new Oauth Twitch Api Authentication
;Originally by Neo Nemesis (YouTube Reader) updated by Lightningsoul.com // Lightningsoul.de

alias twitch {

  %twitchCallUrl = $remove($1,https://,www.,twitch,.tv)
  sockopen twitch www.twitch.tv 443
  sockopen -e twitchprofile api.twitch.tv 443
  %twitchCallUrlAPI = /kraken/streams $+ %twitchCallUrl $+ ?client_id=[YOURAPIKEY]

}

on *:SOCKOPEN:twitch: {

  sockwrite -n $sockname GET %twitchCallUrl HTTP/1.1  sockwrite -n $sockname Host: www.twitch.tv  sockwrite -n $sockname Connection: Keep-Alive  sockwrite -n $sockname Content-Type: text/html  sockwrite -n $sockname $crlf

}

on *:SOCKOPEN:twitchprofile: {

  sockwrite -n $sockname GET %twitchCallUrlAPI HTTP/1.1
  sockwrite -n $sockname Host: api.twitch.tv
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname $crlf

}

on *:sockread:twitchprofile:{

  if ($sockerr > 0) return
  :nextread
  sockread -f %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  if (_id isin %temp) {
    %twitchLive = 1
    if ("stream" isin %temp) {
      %twitchGameStart = $pos(%temp, game, 1)
      %twitchGameEnd = $pos(%temp, viewers, 1)
      %twitchGameBetween = $calc(%twitchGameEnd - %twitchGameStart)
      %twitchGame = $mid(%temp, $calc(%twitchGameStart +5), $calc(%twitchGameBetween - 7))
      %twitchGame = $remove(%twitchGame, ")
      %twitchGame = $replace(%twitchGame, :,)
      msg %ircChan %twitchTeaserText 6,0 Game: %twitchGame  

    }

    if (viewers isin %temp) {

      %twitchViewersStart = $pos(%temp, viewers, 1)
      %twitchViewersEnd = $pos(%temp, video_height, 1)
      %twitchViewersBetween = $calc(%twitchViewersEnd - %twitchViewersStart)
      %twitchViewers = $mid(%temp, $calc(%twitchViewersStart +8), $calc(%twitchViewersBetween - 10))
      %twitchViewers = $remove(%twitchViewers, ")
      %twitchViewers = $replace(%twitchViewers, :, )
      msg %ircChan %twitchTeaserText 6,0 Viewers: %twitchViewers 

      echo -ag %temp

    }

  }

   goto nextread

}

on *:SOCKCLOSE:twitchprofile: {

  if (%twitchLive == 1) {
    msg %ircChan %twitchTeaserText 6,0 LIVE
  }
  else {

    msg %ircChan %twitchTeaserText 6,0 OFFLINE
  }

}

on *:SOCKREAD:twitch: {

  sockread %twitchResponse
  if (%twitchResponse == $null) && (%lgsr == $null) {
    msg %ircChan 0,6 TWITCH15,1 Error receiving information.
    set %lgsr 1

  }

  elseif (%twitchResponse == $null) && (#sockread != $null) { noop }
  else %endtitle2 = $pos(%twitchResponse,/>,1)
  %starttitle2 = $pos(%twitchResponse, %starttitle3 = $pos(%twitchResponse,",1))
  %inbetween3 = $calc(%endtitle2 - %starttitle3)

}

on *:TEXT:*twitch.tv*:#: {

  %ircChan = $chan
  %twitchResponseWord = 1
  %twitchTeaserText = 0,6 TWITCH
  while ([ $chr(36) $+ [ %twitchResponseWord ] ]) {
    if (twitch.tv/ isin [ $chr(36) $+ [ %twitchResponseWord ] ]) {

      sockclose twitch
      sockclose twitchprofile
      %twitchLive = 0
      twitch [ $chr(36) $+ [ %twitchResponseWord ] ]

    }

    inc %twitchResponseWord

  }

}

 

Den API Key [YOURAPIKEY] bekommt ihr übrigens hier, wenn ihr eine neue App bei Twitch erstellt.

Dankeschön auch nochmal an Kati, #help.script (Quakenet) und Neo Nemesis für die Hilfe bei der Programmierung bzw. die Vorarbeit!

comments powered by Disqus