mIRC Home    About    Download    Register    News    Help

Print Thread
#84849 01/06/04 09:30 AM
Joined: Dec 2002
Posts: 124
B
bloupx Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Dec 2002
Posts: 124
i wrote this little script that downloads the latest comic strip and saves it on C:\

the problem is it won't open.
when i use internet explorer to browse to the comic and open it in editor it looks exactly the same to me, except for a blank line my downloaded one has. if i remove the line it still won't open. and i have no idea how to have it not write the blank line. i tried if !$bvar(&r,1,99999) { do nothing } ..but it still writes it to the file. any help would be appreciated.


alias life {
var %d = $+(life.,$r(1,999999),$r(a,z))
sockopen %d www.reallifecomics.com 80
sockmark %d $1-
}
on *:sockopen:life.*:{
if !$sockerr {
var %s = sockwrite -n $sockname,%m = $sock($sockname).mark
%s GET $iif(%m,%m,/index.php) HTTP/1.0
%s Accept: */*
;%s Referer: http://www.reallifecomics.com/daily.php?strip_id=1203
%s Accept-Language: de-ch
%s User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
%s Host: www.reallifecomics.com
%s Pragma: no-cache
%s $crlf
}
}
on *:sockread:life.*:{
var %n = $sockname,%m = $sock(%n).mark,%r
if (*.png iswm %m) sockread &r
else sockread %r
if (*.png !iswm %m) {
tokenize 32 %r
if (Content-Type: image/* iswm $1-) {
var %f = $+($gettok($gettok(%m,3,61),1,38),.,$gettok($2,2,47))
sockmark %n %f
if ($isfile(C:\ $+ %f)) .remove C:\ $+ %f
}
if ($+(<img src='/index.php?do_command=show_strip&strip_id=,*,&,*'*) iswm $1-) {
life $gettok($1-,2,39)
sockclose $sockname
return
}
}
else {
while $sockbr {
bwrite C:\ $+ %m -1 -1 &r
sockread &r
}
}
}


#84850 02/06/04 11:40 AM
Joined: May 2003
Posts: 79
A
Babel fish
Offline
Babel fish
A
Joined: May 2003
Posts: 79
I also tried to code it, and I got the same result as you did, a file that won't open evem if it seems correct (no http header in the file for example). I don't know where the problem was from.

#84851 02/06/04 12:29 PM
Joined: Apr 2004
Posts: 865
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 865
That blank line is HTTP's end-of-header marker. Everything before (and including) the blank line is not part of the actual file, so you need to skip everything up to and including that blank line, before you start writing to the file. The following SOCKREAD-event does just that, and should do what you want:

Code:
on *:sockread:life.*:{
  while (*.png 1 !iswm $sock($sockname).mark) {
    var %r | sockread %r | tokenize 32 %r
    if ($sockbr == 0) return
    if (Content-Type: image/* iswm $1-) {
      var %f = $+($gettok($gettok($sock($sockname).mark,3,61),1,38),.,$gettok($2,2,47))
      sockmark $sockname %f
      if ($isfile(C:\ $+ %f)) .remove C:\ $+ %f
    }
    elseif ($+(&lt;img src='/index.php?do_command=show_strip&amp;strip_id=,*,&amp;,*'*) iswm $1-) {
      life $gettok($1-,2,39)
      sockclose $sockname
      return
    }
    elseif (!$len(%r)) sockmark $sockname $sock($sockname).mark 1
  }
  tokenize 32 $sock($sockname).mark
  sockread &amp;r
  while ($sockbr) {
    bwrite C:\ $+ $1 -1 -1 &amp;r
    sockread &amp;r
  }
}

You also might want to add a SOCKCLOSE event, to see when it's done. In my experience, reallifecomics.com can be quite slow from time to time. smile


Saturn, QuakeNet staff
#84852 02/06/04 01:35 PM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Something like this maybe... smile

on *:sockclose:life.*:{
  • var %f = C:\ $+ $gettok($sock($sockname).mark,1,32)
    window -pdof @Comic -1 -1 $pic(%f).width $pic(%f).height
    drawpic -c @comic 0 0 %f
}



#84853 02/06/04 08:39 PM
Joined: Dec 2002
Posts: 124
B
bloupx Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Dec 2002
Posts: 124
Thanks guys for the answers, i now just trigger another sockread event before reading the data in a binvar so the blank line is being skipped.

some of the images are in .gif format and /drawpic wont load them in, guess i need the nhtmln.dll there, or does anyone have another idea?

i didnt know about the $pic identifier, that one sure comes in handy. thanks.

#84854 02/06/04 10:28 PM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Ah. I assumed that because the line "if (*.png iswm %m)" the pics would all be in .png format.
No there isn't much you can do in the case of GIFs, except maybe to convert them first with a prog such as the excellent and free Irfanview.


This assumes irfanview is installed to the default 'C:\program files\irfanview\' folder.

alias gif2png {
  • tokenize 32 $remove($1-,")
    if $gettok($1-,-1,46) != gif { return }
    var %a = $ticks,%x = $+(",$1-,"),%y = $+(",$puttok($1-,png,-1,46),")
    .comopen %a wscript.shell
    if !$comerr {
    .comclose %a $com(%a,run,3,bstr,C:\progra~1\irfanv~1\i_view32.exe %x /convert= $+ %y,uint,7,bool,true)
    }
    return %y
}

In your sockclose event, you check the extension for GIF and convert if needed.

on *:sockclose:life.*:{
  • var %f = C:\ $+ $gettok($sock($sockname).mark,1,32)
    if $gettok(%f,-1,46) isin gif" { %f = $gif2png(%f) }
    window -pdof @Comic -1 -1 $pic(%f).width $pic(%f).height
    drawpic -c @comic 0 0 %f
}

Best I can do... smirk


Link Copied to Clipboard