mIRC Home    About    Download    Register    News    Help

Print Thread
A little socket help #234695 07/11/11 12:51 PM
Joined: Aug 2006
Posts: 182
T
Thrull Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2006
Posts: 182
I'm trying to pull information off of http://174.142.79.66:8278/index.html

However, whenever I try and access the site via sockets, I get a bunch of gobbly-gook streaming in, I assume this is the music being played. All I want is the text that I see in my browser.

Here's the code I'm using the currently produces the gobbly-gook.

Code:
Alias Radio {
  sockopen Radio40 174.142.79.66 8278
  ;the below line is there to ensure that Mirc doesn't freeze up when it starts being hit by all the gobbly-gook
  timer 1 2 sockclose Radio40
}

on 1:sockopen:radio40: {
  window -e @radio
  sockwrite -n radio40 GET / HTTP/1.1
  ;sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
  sockwrite -n $sockname Host: 174.142.79.66 $+ $crlf $+ $crlf
  sockwrite -n radio40 Accept-Charset: text/html; charset=windows-1252
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; rv:1.7.3) Gecko/20040913 Firefox/0.10.1
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}

on *:sockread:radio40: {
  sockread %radio40.temp
  echo @radio %radio40.temp
}


Thanks


Yar
Re: A little socket help [Re: Thrull] #234696 07/11/11 12:56 PM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Quote:

Code:
  sockwrite -n $sockname Host: 174.142.79.66 $+ $crlf $+ $crlf



get rid of those CRLFs. an empty line signals the end of your HTTP request.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: A little socket help [Re: jaytea] #234697 07/11/11 01:08 PM
Joined: Aug 2006
Posts: 182
T
Thrull Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2006
Posts: 182
Thanks, that got rid of the spam, but now it just returns

HTTP/1.0 200 OK
content-type:text/html


Yar
Re: A little socket help [Re: Thrull] #234704 07/11/11 06:16 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Code:
alias radio {
  if ($window(@radio)) clear @radio
  sockopen Radio40 174.142.79.66 8278
}
on *:sockclose:radio40:{
  echo @radio Server Status: Server is currently down.
}
alias -l getinfo {
  return $regsubex($bvar(&radio.temp,1-).text,/<[^>]*>|&nbsp;|<.*/g,$chr(32))
}
on *:sockopen:radio40:{
  window -e @radio
  sockwrite -n $sockname GET / HTTP/1.1
  sockwrite -n $sockname Host: 174.142.79.66
  sockwrite -n $sockname Accept-Charset: text/html; charset=windows-1252
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; $&
    Windows NT 5.2; rv:1.7.3) Gecko/20040913 Firefox/0.10.1
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}
on *:sockread:radio40:{
  sockread &radio.temp
  if ($regex($getinfo,/(server status.*) stream/i)) echo @radio $regml(1)
  if ($regex($getinfo,/d>(.*\s\050.*\051)/i)) echo @radio Stream Status: $regml(1)
  if ($regex($getinfo,/(listener peak: \d+)/i)) echo @radio $regml(1)
  if ($regex($getinfo,/(average listen time:.*)/i)) echo @radio $gettok($regml(1),1-5,32)
  if ($regex($getinfo,/(stream title:.*)content/i)) echo @radio $regml(1)
  if ($regex($getinfo,/(content type:.*)/i)) {
    tokenize 32 $regml(1) 
    echo @radio $1-3
    echo @radio $4-6
    echo @radio $7-9
    echo @radio $11-12
    echo @radio $13-15
    echo @radio $16-18
    sockclose $sockname
  }
}



Last edited by Tomao; 07/11/11 10:14 PM.
Re: A little socket help [Re: Thrull] #234706 07/11/11 08:34 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
I can't test right now, so I don't know exactly what "gobbly-gook" you are seeing, but HTTP/1.1 often sends data in chunks. This can cause some confusion when trying to work with it. You might try using HTTP/1.0 and see if that makes it easier for what you're doing.


Invision Support
#Invision on irc.irchighway.net
Re: A little socket help [Re: Riamus2] #234708 07/11/11 09:51 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
HTTP/1.1 works just as dandy.

Last edited by Tomao; 07/11/11 10:03 PM.
Re: A little socket help [Re: Riamus2] #234709 07/11/11 09:54 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
His code is actually trying to listen to the radio, after the header he will constantly receive data, which does freeze mIRC if you have an echo on each data received.
Also, "1.1" doesn't necessarily send data as chunk


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: A little socket help *DELETED* [Re: Tomao] #234710 07/11/11 10:06 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Post deleted by Tomao

Re: A little socket help [Re: Tomao] #234711 07/11/11 10:35 PM
Joined: Jul 2006
Posts: 3,558
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,558
Use sockread -n on the binvar


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: A little socket help [Re: Wims] #234712 07/11/11 10:40 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Yeah, I should have said "usually" or "often" there. I fixed it. smile


Invision Support
#Invision on irc.irchighway.net
Re: A little socket help *DELETED* [Re: Tomao] #234722 08/11/11 03:58 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Wims, that didn't work with the -n switch. Anyway, I've worked it out and here is the finished product:
Code:
alias radio {
  if ($window(@radio)) clear @radio
  sockopen Radio40 174.142.79.66 8278
}
on *:sockopen:radio40:{
  if (!$sockerr) {
    window -e @radio
    sockwrite -n $sockname GET / HTTP/1.1
    sockwrite -n $sockname Host: 174.142.79.66
    sockwrite -n $sockname Accept-Charset: text/html; charset=windows-1252
    sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; $&
      Windows NT 5.2; rv:1.7.3) Gecko/20040913 Firefox/0.10.1
    sockwrite -n $sockname Connection: Close | sockwrite -n $sockname $crlf
  }
}
alias -l getinfo {
  return $regsubex($bvar(&radio.temp,1-).text,/<[^>]*>|&nbsp;|<.*|\t/g,$chr(32))
}
on *:sockread:radio40:{
  if (!$sockerr) {
    sockread &radio.temp
    if (Server is currently down isin $getinfo) echo @radio Server Status: $v1 $+ .
    else {
      if ($regex($getinfo,/(current song:.*)written/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(server status.*) stream/i)) echo @radio $regml(1)
      if ($regex($getinfo,/d>(.*\s\050.*\051)/i)) echo @radio Stream Status: $regml(1)
      if ($regex($getinfo,/(listener peak: \d+)/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(average listen time:.*)/i)) echo @radio $gettok($regml(1),1-5,32)
      if ($regex($getinfo,/(stream title:.*)content/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(content type:.*)/i)) {
        tokenize 32 $regml(1) | echo @radio $1-3 | echo @radio $4-6 | echo @radio $7-9 
        echo @radio $11-12 | echo @radio $13-15 | echo @radio $16-18
      }
    }
  }
}
I've added the output for Stream URL, ICQ, AIM and IRC because sometimes they do show their info, sometimes they're not applicable.

Re: A little socket help [Re: Thrull] #234730 08/11/11 07:52 AM
Joined: Aug 2006
Posts: 182
T
Thrull Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2006
Posts: 182
Ok, thank you kindly guys. I really just needed to know how to get the info, I'd have parsed it myself. But thanks for the extra work. Makes my life just a bit easier.

Haven't tested it while the stream is running, but I shall soon.

Thanks again!


Yar
Re: A little socket help *DELETED* [Re: Tomao] #234741 08/11/11 06:05 PM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Well, using tokenize may not be ideal because some of the token lengths are variable, so I think it'd be best to do:
Code:
alias radio {
  if ($window(@radio)) clear @radio
  sockopen Radio40 174.142.79.66 8278
}
on *:sockopen:radio40:{
  if (!$sockerr) {
    window -e @radio
    sockwrite -n $sockname GET / HTTP/1.1
    sockwrite -n $sockname Host: 174.142.79.66
    sockwrite -n $sockname Accept-Charset: text/html; charset=windows-1252
    sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; $&
      Windows NT 5.2; rv:1.7.3) Gecko/20040913 Firefox/0.10.1
    sockwrite -n $sockname Connection: Close | sockwrite -n $sockname $crlf
  }
}
alias -l getinfo {
  return $regsubex($bvar(&radio.temp,1-).text,/<[^>]*>|&nbsp;|<.*|\t/g,$chr(32))
}
on *:sockread:radio40:{
  if (!$sockerr) {
    sockread &radio.temp
    if (Server is currently down isin $getinfo) echo @radio Server Status: $v1 $+ .
    else {
      if ($regex($getinfo,/(server status.*)stream/i)) echo @radio $regml(1)
      if ($regex($getinfo,/d>(.*)listener/i)) echo @radio Stream Status: $regml(1)
      if ($regex($getinfo,/(listener peak.*)average/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(average listen time:.*)/i)) echo @radio $gettok($regml(1),1-5,32)
      if ($regex($getinfo,/(content type:.*)stream/i)) echo @radio $gettok($regml(1),1-3,32)
      if ($regex($getinfo,/(stream genre:.*)stream url/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(stream url:.*)stream (icq|aim)/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(stream icq:.*)stream (icq|aim)/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(stream aim:.*)stream irc/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(stream irc:.*)current/i)) echo @radio $regml(1)
      if ($regex($getinfo,/(current song:.*)/i)) echo @radio $regml(1)
    }
  }
}