|
|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
hi, i am trying to make a socket script to grab lyrics from a web page, and i am having a heck of a time doing it. the script below is what i have so far, but it keeps freezing mirc and i end up having to kill it with task manager.
;===================================================================================
; Socket Stuff for Lyrics Search
;===================================================================================
alias lyrics {
echo -a Converting Data Into Query
var %artist artist= $+ $$?="ARTIST NAME"
var %title &title= $+ $$?="SONG TITLE"
var %temp %artist $+ $chr(32) $+ %title
var %query $replace(%temp,$chr(32),$chr(37) $+ 20)
echo -a %query
sockopen lyrics lyricsplugin.com 80
}
on *:sockread:lyrics:{
if ($sockerr) {
echo -a WARNING: An Error Occurred
halt
}
else {
sockread %'
window @lyrics
while ( $sockbr != 0 ) { aline @lyrics %' }
sockclose $sockname
halt
}
}
on *:sockopen:lyrics:{
echo -a Getting info for: %query
sockwrite -n $sockname GET /plugin/? $+ %query HTTP/1.1
sockwrite -n $sockname Host: www.lyricsplugin.com
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname $crlf
}
alias nohtml {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
return %x
}
All this does is write out something like: http: 200 ok or http: 300 found is my script totally screwed up, or is it salvagable? thanks
keek: Scots - intr.v. keeked, keek·ing, keeks To peek; peep.
|
|
|
|
Joined: Jun 2006
Posts: 508
Fjord artisan
|
Fjord artisan
Joined: Jun 2006
Posts: 508 |
2 things. 1. You set %query as a local var, so it wont be available in the sockopen event you should /set it (global) and unset at the end of sockopen event 2. these lines while ( $sockbr != 0 ) { aline @lyrics %' }
sockclose $sockname should be more like while ( $sockbr ) {
if $nohtml(%') { aline @lyrics $v1 }
[color:blue]sockread %'[/color]
} (no need for /sockclose, it will be closed anyway EDIT: Make that 3 things.. var %temp %artist $+ $chr(32) $+ %title shouldnt have a $chr(32) between the vars, no need for %temp anyway set %query $replace($+(%artist,%title),$chr(32),$(%20,0))
Last edited by deegee; 01/11/06 09:04 PM.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
also try using HTTP/1.0 insted of 1.1 and see if it helps
|
|
|
|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
well, hot diggity dog, i made al the changes you and mikechat said, and wouldnt ya know it? the dang thing works. thanks alot pardners!!
oops one more question though, and i dont really want to start a new thread. what do i have to do to catch only one part of the page, like i only want to catch something like this
<div id=lyrics> ... ....she broke my heart.... ....she broke it, and i dont know what to do.... ... </div>
i just want to catch the part between those two tags.
make any sense?
Last edited by keeker; 01/11/06 10:16 PM.
keek: Scots - intr.v. keeked, keek·ing, keeks To peek; peep.
|
|
|
|
Joined: Jun 2006
Posts: 508
Fjord artisan
|
Fjord artisan
Joined: Jun 2006
Posts: 508 |
on *:sockread:lyrics:{
if ($sockerr) { echo -a WARNING: An Error Occurred: $sock($sockname).wsmsg }
; check that %lyrical does NOT exist
if (!%lyrical) {
sockread %' | ; read and discard...
if (*<div id="lyrics">* iswm %' ) { set -s %lyrical 1 }
}
; now that the var exists, read and display
else {
sockread %'
window @lyrics
while ($sockbr) {
if $nohtml(%') { aline @lyrics $v1 }
sockread %'
; until the </div> tag
if (*</div>* iswm %') { unset -s %lyrical | return }
}
}
}
|
|
|
|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
keek: Scots - intr.v. keeked, keek·ing, keeks To peek; peep.
|
|
|
|
|
|