mIRC Home    About    Download    Register    News    Help

Print Thread
#234695 07/11/11 12:51 PM
Joined: Aug 2006
Posts: 183
T
Thrull Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
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
Joined: Feb 2006
Posts: 546
J
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
Joined: Aug 2006
Posts: 183
T
Thrull Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
Thanks, that got rid of the spam, but now it just returns

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


Yar
Joined: Jul 2007
Posts: 1,129
T
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.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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
Joined: Jul 2007
Posts: 1,129
T
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.
Joined: Jul 2006
Posts: 4,164
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,164
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Post deleted by Tomao

Joined: Jul 2006
Posts: 4,164
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,164
Use sockread -n on the binvar


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Yeah, I should have said "usually" or "often" there. I fixed it. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
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.

Joined: Aug 2006
Posts: 183
T
Thrull Offline OP
Vogon poet
OP Offline
Vogon poet
T
Joined: Aug 2006
Posts: 183
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
Joined: Jul 2007
Posts: 1,129
T
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)
    }
  }
}


Link Copied to Clipboard