mIRC Home    About    Download    Register    News    Help

Print Thread
socket variable data read #145660 26/03/06 08:22 AM
Joined: Mar 2006
Posts: 10
S
strac Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Mar 2006
Posts: 10
I am currently working on a script for Net Radio Broadcasting. I am looking for the bot to be able to display the current playing song on the server, so that it will display as <NowPlaying> Artist - Title I have a php script that simply displays Artist - Title but I'm running into the problem that the script displays all the extra information. Here is the script thus far:

alias wwwleech {
if (!$1-) { tokenize 32 http://darksideofthelake.com/bplaying.php 80 }
; /wwwleech <site and file> <port>
var %sn = $+(wwwleech.,$ticks)
sockopen %sn $gettok($1-,2,47) $iif(!$2,80,$2)
sockmark %sn $iif(!$2,$1-,$deltok($1-,-1,32))
}
on 1:sockopen:wwwleech.*:{
if ($sockerr) { echo -s error: $sock($sockname).wserr | return }
sockwrite -n $sockname GET $sock($sockname).mark HTTP/1.1
sockwrite -n $sockname ACCEPT: */*
sockwrite -n $sockname USER-AGENT: Mozilla
sockwrite -n $sockname CONNECTION: CLOSE
sockwrite -n $sockname HOST: $gettok($sockname,2,47)
sockwrite -n $sockname $crlf
}
on 1:sockread:wwwleech.*:{
if ($sockerr) { echo -s error: $sock($sockname).wserr | return }
:read
sockread %tmp
if ( * iswm %tmp) { if (%tmp != %lastplayed) { %lastplayed = %tmp | .signal -n newsong %tmp } }
if ($sockbr) { goto read }
}
on 1:sockclose:wwwleech.*:{ if ($sockerr) { echo -s socket error: $sock($sockname).wsmsg } }
on 1:signal:newsong:{

/msg #lobby %lastplayed

}


can anyone help me with this problem?

Re: socket variable data read #145661 26/03/06 07:42 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I modified your code slightly and it works as it is:
Code:
alias wwwleech {
  if (!$1-) { tokenize 32 http://darksideofthelake.com/bplaying.php 80 }
  ; /wwwleech &lt;site and file&gt; &lt;port&gt;
  var %sn = $+(wwwleech.,$ticks)
  sockopen %sn $gettok($1-,2,47) $iif(!$2,80,$2)
  sockmark %sn $iif(!$2,$1-,$deltok($1-,-1,32))
}
on 1:sockopen:wwwleech.*:{
  if ($sockerr) { echo -s error: $sock($sockname).wserr | return }
  sockwrite -n $sockname GET $sock($sockname).mark HTTP/1.0
  sockwrite -n $sockname CONNECTION: CLOSE
  sockwrite -n $sockname HOST: $gettok($sockname,2,47) 
  sockwrite -n $sockname
}
on 1:sockread:wwwleech.*:{
  if ($sockerr) { echo -s error: $sock($sockname).wserr | return }

  var %tmp
  sockread %tmp
  if (%tmp == $null) set %nextline 1
  elseif (%nextline) { 
    if (%tmp != %lastplayed) {
      %lastplayed = %tmp 
      .signal -n newsong %tmp 
    }
    unset %nextline
    sockclose $sockname
  }
}
on 1:sockclose:wwwleech.*:{ if ($sockerr) { echo -s socket error: $sock($sockname).wsmsg } }
on 1:signal:newsong:{ 

  /msg #lobby %lastplayed

}


If you are able to modify the php output, you could give it a parsable format, then the code would be even simpler. The output could be something like this:

Artist - Song Title

(Notice the special character). This unique character could be used in a regex/wildcard comparison to immediately identify the correct line in the html code. Using that above example, this sockread event could be used to parse the line:
Code:
on 1:sockread:wwwleech.*:{
  if ($sockerr) { echo -s error: $sock($sockname).wserr | return }

  var %tmp
  sockread %tmp
  tokenize 32 %tmp
  if ( * iswm $1-) { 
    if ($2- != %lastplayed) {
      %lastplayed = $2- 
      .signal -n newsong $2- 
    }
    unset %nextline
    sockclose $sockname
  }
}


-genius_at_work

Re: socket variable data read #145662 26/03/06 09:32 PM
Joined: Mar 2006
Posts: 10
S
strac Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: Mar 2006
Posts: 10
I knew I had a brainfart somewhere, I do have control over the php output and I did try to use a . as my line marker, I haven't done enough mirc scripting in a long time to remember quite exactly where I needed to place the $2- so I instead sided with changing the php output to be strictly the Artist - Title thinking that would have been easier.