mIRC Home    About    Download    Register    News    Help

Print Thread
Switch - script that checks if stream is live? #250212 05/01/15 09:44 PM
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
I was browsing on here and found this !uptime script.

This had me thinking that if one can check the uptime of a stream that it would be possible to have mIRC simply check if a stream is live, and if so, do something.

Right now, I am figuring every 20-30 seconds, the script would check if my stream is live, and if it is run a timer and send a message to the chat

if live
.timertest 0 23 fancy timer thing here
msg $chan timer started

Does anything think this can be done? or know how to point me in the right direction?

Last edited by jimieo; 06/01/15 12:37 AM.
Re: Switch - script that checks if stream is live? [Re: jimieo] #250230 06/01/15 01:41 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
You need to change the uptime script so it sets the uptime (if present) to a variable (e.g %uptime), and also have it unset %uptime and %target at the beginning.

Then I imagine you would need something like this

Code:
on *:connect:{ timer1 0 30 streamcheck } 

alias -l streamcheck {

uptime

if ( %uptime ) && (%target = YourChannelName) {

timer1 off
timer2 0 30 msg # text goes here

   }   
}



But you should make it say different lines. Getting spammed with the same timed message is pretty obnoxious :p

Last edited by Sakana; 06/01/15 02:56 AM.
Re: Switch - script that checks if stream is live? [Re: Sakana] #250232 06/01/15 04:37 AM
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
I'll check that out in a moment.

I agree about the message. The plan is to have it say the message once while the timer runs until the uptime variable is set to 0, when the show ends.

Re: Switch - script that checks if stream is live? [Re: jimieo] #250234 06/01/15 06:44 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Maybe there's something more optimal, but this works as intended when I tested it. Just replace all instanes of STREAMNAME with your Twitch name

Code:
on *:connect:{ timer1 0 30 StreamCheck } 

alias StreamCheck {
   StreamOn STREAMNAME
  .timer 1 2 Streamcheck2   
}

alias StreamCheck2 {
    if (%uptime) && (%target = STREAMNAME)  {
    timer1 off
    timer2 0 30 msg #STREAMNAME text goes here
}   
    else echo -a StreamCheck error
}

alias StreamOn {
  unset %target
  unset %uptime
  set %target $iif($1,$1,$mid(#,2-)) 
  sockclose StreamOn
  sockopen StreamOn nightdev.com 80
}

on *:sockopen:StreamOn:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /hosted/uptime.php?channel= $+ %target HTTP/1.1
  sockwrite -n $sockname Host: www.nightdev.com
  sockwrite -n $sockname $crlf
}

on *:sockread:StreamOn:{
  if ($sockerr) { sockclose $sockname | halt }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { set %uptime $1- }
}


Last edited by Sakana; 06/01/15 07:27 AM.
Re: Switch - script that checks if stream is live? [Re: Sakana] #250235 06/01/15 08:32 AM
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
Thank you, Sakana, for the time you have invested in this. I truly appreciate the work.

Re: Switch - script that checks if stream is live? [Re: jimieo] #250466 16/01/15 06:27 AM
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
Hrmm.. While yes, this does work. I've been encountering issues lately.

For starters I use this script to start some timers that I only want to run while I am live. But lately, I've been having issues where it turns them off and back on frequently. The script isn't always able to tell my stream is live.

Does anyone know if there is a better method, using twitch's API or something?

Re: Switch - script that checks if stream is live? [Re: jimieo] #250467 16/01/15 06:28 AM
Joined: Jun 2014
Posts: 248
B
Belhifet Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Get a json parser and use the https://api.twitch.tv/kraken/streams/ endpoint

Re: Switch - script that checks if stream is live? [Re: Belhifet] #250468 16/01/15 08:03 AM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
Originally Posted By: Belhifet
Get a json parser and use the https://api.twitch.tv/kraken/streams/ endpoint


Parser: JSON for MIRC,

Though I'd recommend AGAINST looping over the entirety of the streams list, instead use https://api.twitch.tv/kraken/streams/<username>

Last edited by FroggieDaFrog; 16/01/15 08:07 AM.

I am SReject
My Stuff
Re: Switch - script that checks if stream is live? [Re: FroggieDaFrog] #250497 18/01/15 08:43 AM
Joined: Jan 2015
Posts: 40
J
jimieo Offline OP
Ameglian cow
OP Offline
Ameglian cow
J
Joined: Jan 2015
Posts: 40
Thanks. Looking up how to use the api now smile

EDIT:
Code:
on *:text:!hmm*:#:{
  if ($nick == jimieo) {
    var %twitchapi = https://api.twitch.tv/kraken/streams/jimieo
    set %game $json(%twitchapi,stream,game)
  }
}


So, I was trying this to see if I could get it to set the game as a variable (just to see if I could). I failed. Did I just miss something stupidly obvious.

My end goal is to be able to detect if my channel shows as live or not.

Last edited by jimieo; 18/01/15 09:15 AM.
Re: Switch - script that checks if stream is live? [Re: jimieo] #250500 18/01/15 12:53 PM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
A few things:
1: On text events do not trigger for the client that sends them. That is the same client that sends "!hmm" will not trigger it's own on text event

2: Read the scripts documentation:

Code:
  jsonopen -ud twitchapi https://api.twitch.tv/kraken/streams/jimieo
  set %game $json(twitchapi, stream, game)


I am SReject
My Stuff