ExPlOsM.NeT Comic Downloader/Viewer (v.4)

By Kirby on Apr 10, 2009

Another example of the power of binaries and hashes to produce image downloading, however slightly modified.

Basically, the script gets a random webcomic from Cyanide and Happiness Comics, downloads it, and then opens it for you to view.

[size=18]Syntax: /explosm[/size]

[size=16]You can also download and view images via menu, including emptying/deleting directories, as shown in the picture below.[/size]

[size=16]While in the window @ExPlOsM, you can press the Enter Key or the Spacebar to download and view another image from the website![/size]

[size=16]All images are downloaded to a folder called explosm.net in your mIRC Directory.[/size]

[size=16][b]An echo regarding information on the www.explosm.net comic download is made to the Status Window.

[Cyanide and Happiness ~ X] ~ Comic: http://www.explosm.net/comics/XXXX/ ~ Submitter: Nick ~ Date: X XX XXXX ~ Direct link: http://www.explosm.net/db/files/Comics/XXXXXXXXXX.XXX

If you want for it to echo in your active channel/query, change the timer to this:

  .timerexplosm 1 2 echo -e $lactive [Cyanide and Happiness ~ $+($calc($findfile(explosm.net,*,0,0) + 1),]) ~ Comic: $+(,$+(http://,$sock(explosm2).addr,$1),) ~ Submitter: $+(,$3,) ~ Date: $+(,$gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,$gettok($4,1,46),32) $ord($abs($gettok($4,2,46))) $gettok($4,3,46),) ~ Direct link: $+(,$2,)

[/b][/size]

[size=14]*** Note: mIRC Version 6.35 works most effectively. Download it here if you want to experience best possible results[/size].

[size=14]Thanks to ^Neptune for introducing me to this and TheImrac for the awesome alias.[/size]

Here's a picture:
Image

Here's another picture:
Image

Enjoy! :D

;SOF

;~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*;
;         Explosm Cyanide & Happiness WebComic         ;
;               Made by Kirby (Quakenet)               ;
;*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~;

; // ... Download + View a comic ... Syntax: /explosm ... //
alias explosm {
  if (!$sock(explosm)) && (!$sock(explosm2)) sockopen explosm www.explosm.net 80
}

; // Download + View a comic / Clear Directory //
menu * {
  ExPlOsM.NeT~! $+($chr(40),$findfile(explosm.net,*,0,0) $iif($findfile(explosm.net,*,0,0) == 1,comic,comics),$chr(41))
  .Download + View $iif($findfile(explosm.net,*,0,0) == 0,a,another) comic : explosm
  .$iif($abs($findfile(explosm.net\,*,0,0)) == 0,$style(6) Clear bin,$style(4) Clear bin) : noop $findfile(explosm.net\,*,0,0,.remove $qt($1-)) | noop $input(Done. Deleted all files in the directory $mircdirexplosm.net,iok2,Attention!)
  .$iif($abs($findfile(explosm.net\,*,0,0)) != 0,$iif($isdir(explosm.net),$style(4) Delete all,$style(6) Delete all),$style(6) Delete all) : noop $findfile(explosm.net\,*,0,0,.remove $qt($1-)) | rmdir explosm.net | noop $input(Done. Deleted directory $mircdirexplosm.net,iok2,Attention!)
  .-
  .$iif($isdir(explosm.net),$style(4) Open comic folder,$style(6) Open comic folder) : run $mircdirexplosm.net
}

; // Identifiers used in the sockets //
alias -l addmark { return $+($sock($1).mark,$chr($3),$2) }
alias -l between { noop $regex($1,/\Q $+ $2 $+ \E(.*?)\Q $+ $3 $+ \E/gi) | return $regml($4) }
alias -l htmlfree { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;) | return $remove($replace(%x,&quot;,",&lt;,<,&gt;,>,$cr,$chr(32),$lf,$chr(32),&amp;,&,&#34;,",&#226;,$chr(226),&#183;,·,&#233;,é,&#38;,$chr(38),&#x22;,",&#x27;,',&#x26;,&,&#xF4;,ô,&#xB7;,·,&#xE9;,é),$chr(9)) }

; // ExPlOsM.NeT WebComic Socket Step #1 (Get link) //
on *:sockopen:explosm: {
  sockwrite -n $sockname GET /comics/random/ HTTP/1.1
  sockwrite -n $sockname Host: www.explosm.net $+ $crlf $+ $crlf
}
on *:sockread:explosm: {
  sockread %explosm
  if (Location: isin %explosm) sockmark explosm $gettok($v2,2,32))
}
on *:sockclose:explosm: {
  sockopen explosm2 www.explosm.net 80
  sockmark explosm2 $sock(explosm).mark
}

; // ExPlOsM.NeT WebComic Socket Step #2 (Download image) //
on *:sockopen:explosm2: {
  sockwrite -n $sockname GET $sock(explosm2).mark HTTP/1.1
  sockwrite -n $sockname Host: www.explosm.net $+ $crlf $+ $crlf
}
on *:sockread:explosm2: {
  sockread %explosm2
  if (<td width=240> isin %explosm2) sockmark explosm2 $addmark(explosm2,$+($between($v2,a daily webcomic" src=","></div>,1),$chr(32),$htmlfree($between($v2,$+(<b>by,$chr(32)),</b>,1)),$chr(32),$between($v2,colspan=2>,$+($chr(32),<b>),1)),32)
}
on *:sockclose:explosm2: {
  tokenize 32 $sock(explosm2).mark
  if (!$isdir(explosm.net)) mkdir explosm.net
  img_download -oak loadimg $2 explosm.net\
  .timerexplosm 1 2 echo -se [Cyanide and Happiness ~ $+($calc($findfile(explosm.net,*,0,0) + 1),]) ~ Comic: $+(,$+(http://,$sock(explosm2).addr,$1),) ~ Submitter: $+(,$3,) ~ Date: $+(,$gettok(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec,$gettok($4,1,46),32) $ord($abs($gettok($4,2,46))) $gettok($4,3,46),) ~ Direct link: $+(,$2,)
  unset %explosm*
}

;// ExPlOsM.NeT WebComic Viewer (@Window) //
menu @ExPlOsM {
  Minimize comic: window -n @ExPlOsM
  Close comic : window -c @ExPlOsM
}
on *:keydown:@ExPlOsM:*: {
  if (!$keyrpt) {
    if ($keyval == 13) || ($keyval == 32) explosm
    elseif ($keyval == 27) window -c @ExPlOsM
  }
}

;~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~;
;         TheImrac's "Image-Downloader"         ;
;*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*;

alias -l bet { var %reg $+(/,$2,(.+?),$3,/i) | %reg = $regex($1,%reg) | return $regml($4) }
alias img_download {
  if ($regex(par,$1,/^(-[uakmos]{1,6})/i)) {
    var %flgs = $regml(par,1)
    if (a isin %flgs) && (u isin %flgs) { var %a = $2, %u = $3, %1 = $4, %2- $5- }
    elseif (a isin %flgs) { var %a = $2, %1 = $3, %2- $4- }
    elseif (u isin %flgs) { var %a = $2, %1 = $3, %2- $4- }
    else { var %1 = $2, %2- $3- }
  }
  else { var %1 = $1, %2- = $2- }
  if ($regex(img,%1,/^((?:https?://)((?:www.)?[^/]*)(.*/([^/]*\.(jpg|gif|bmp|png))))$/i)) && (%2-) {
    var %f = $qt(%2-)    
    if (k isin %flgs)  {
      if ($nofile(%f) == $noqt(%f)) { var %f = $qt($noqt(%f) $+ $regml(img,4)) }
      else { echo -qeag * /img_download: Invalid Directory Name. | halt }
    }
    if ($exists(%f)) && (o !isin %flgs) { echo -eqag * /imgfile: %f Already Exists. | halt }
    if (!$exists($nofile(%f))) && (m !isin %flgs) { echo -eqag * /img_download: $qt($nofile(%f)) Directory Does Not Exist. | halt }
    if ($right($noqt(%f),3) != $regml(img,5)) { echo -qeag * /img_download: Invalid File Name. | halt }
    else {
      var %x = imgdl_ $+ $regml(img,1)
      hadd -m %x full $regml(img,1)
      hadd %x host $regml(img,2)
      hadd %x get $regml(img,3)
      hadd %x dlfile $regml(img,4)
      hadd %x file %f
      hadd %x time $ticks
      if (%flgs) { hadd %x flgs %flgs }
      if (%a) hadd %x alias %a
      if (%u) hadd %x update %u
      .sockclose %x
      .sockopen %x $hget(%x,host) 80
    }
  }
  else echo -qeag * /img_download: Invalid Parameters.
}
on *:sockopen:imgdl_*:{
  if ($sockerr) { img_fail $sockname }
  else {
    sockwrite -n $sockname GET $hget($sockname,get) HTTP/1.1 
    sockwrite -n $sockname Host: $hget($sockname,host)
    sockwrite -n $sockname
  } 
}
on *:sockread:imgdl_*:{ 
  if ($sockerr) { img_fail $sockname }
  if (!$sock($sockname).mark) { 
    var %x = $true  
    while (%x) { 
      sockread %x
      if ($regex(%x,/^Content-Length: (\d+)$/i)) { hadd $sockname size $regml(1) }
      if ($regex(%x,/^Content-Type: (.*)$/i)) { if (!$regex($regml(1),/^image/.*$/)) { img_fail $sockname | halt } } 
      sockmark $sockname $true 
    }
  }
  else {
    while ($sock($sockname).rq) {
      sockread &img
      noop $hget($sockname,bvar,&temp) 
      bcopy &temp $calc($bvar(&temp,0) + 1) &img 1 -1
      var %size = $bvar(&temp,0)    
      hadd -b $sockname bvar &temp
      if (%size == $hget($sockname,size)) img_close
      else { if ($hget($sockname,update)) { $v1 %size $hget($sockname,size) $calc($ticks - $hget($sockname,time)) $hget($sockname,full) $hget($sockname,file) } }
    }  
  }
}
alias -l img_close {
  var %mz = $calc($ticks - $hget($sockname,time)), %size = $bvar(&temp,0) 
  if (o isin $hget($sockname,flgs)) .remove $hget($sockname,file)
  if (m isin $hget($sockname,flgs)) .mkdir $nofile($hget($sockname,file)) 
  bwrite $hget($sockname,file) -1 -1 &temp    
  if (s isin $hget($sockname,flgs)) {
    var %s = $calc(($ticks - $hget($sockname,time)) / 1000), %sz = $calc($bvar(&temp,0) / 1024) 
    echo -eag Downloaded $hget($sockname,file) ( $+ $round(%sz,2) kb $+ ) Took %s Seconds at $round($calc(%sz / %s ),2) kbps 
  }
  if (r isin $hget($sockname,flgs)) { run $hget($sockname,file) }
  if ($hget($sockname,alias)) { $v1 $hget($sockname,full) %mz %size $pic($hget($sockname,file)).width $pic($hget($sockname,file)).height $hget($sockname,file) }
  hfree $sockname
  sockclose $sockname
}
alias -l img_fail {
  if ($sock($1)) sockclose $1
  if ($hget($1,alias)) { $v1 $hget($sockname,full) }
  hfree $1
}
alias loadimg {
  if (!$2) echo -e Error Downloading File $1
  else {
    if ($window(@ExPlOsM)) window -c @ExPlOsM
    if ($4 > $calc($window(-3).w * .75)) || ($5 > $calc($window(-3).h * .75)) { 
      if ($4 >= $5) { var %w = $round($calc(.75 * $window(-3).w),0), %h = $round($calc(%w * $5 / $4),0) }
      else { var %h = $round($calc(.75 * $window(-3).h),0), %w = $round($calc(%h * $4 / $5),0) }
    }
    else var %w = $4, %h = $5
    window -dapBCw3 +d @ExPlOsM 50 50 %w %h
    drawpic -s @ExPlOsM 0 0 %w %h $6-
  }
}

;EOF

Comments

Sign in to comment.
^Neptune   -  Oct 25, 2009

I like it :). Very good use of msl scripting. - The coding is also great :P.

alias explosm { run www.explosm.net }
 Respond  
gooshie   -  Oct 14, 2009

Ghost-writer
That page contains a flash comic and does not
match up for sending to picture window and even
if it did would not be able to render so echos
the invaled parameter line.
http://www.explosm.net/comics/1706/
http://www.explosm.net/db/files/Movies/signpart2.swf

Perhaps Kirby could do something like:

on *:sockclose:explosm2: {
  tokenize 32 $sock(explosm2).mark
  if (!$isdir(explosm.net)) mkdir explosm.net
  if $4 {
    img_download -oak loadimg $2 explosm.net\
    .timerexplosm 1 2 echo -se [Cyanide and Happiness ~ TRUNCATED CODE
  }
  else { echo -s add code to try again 2-5 times before abort/error }
  unset %explosm*
}

I did just notice that some large comics are shrunk as to make
them unreadable ==> http://www.explosm.net/comics/1403/
Can't figure a good work arround right now.

I still like it tho

 Respond  
Ghost-writer   -  Oct 14, 2009

I like it :). Very good use of msl scripting. - The coding is also great :P.

But alask, nothing is perfect.

[Cyanide and Happiness ~ 8] ~ Comic: http://www.explosm.net/comics/1706/ ~ Submitter: 01.13.2007 ~ Date: ~ Direct link: Rob

  • /img_download: Invalid Parameters.

  • drawpic: error loading 'C:\WINDOWS\DESKTOP\SCHOOL HRP\MARYS MIRC\explosm.net\zchriz.gif' (line 172, script2.ini)
 Respond  
sunslayer   -  Oct 13, 2009

should prolly think about adding a confirmation thing before it deletes the pics

 Respond  
gooshie   -  Oct 13, 2009

This is a well thought out fun addon.
I tried it. It worked. I didn't even
want to look through all that code and
try to find any ways to improve it.
The only thing I did was make it so it
only appears in my top menubar menu.
I may color the link to the webpage
where it echos to status so I can spot
it for copy pasting when I see one I
wish to share. I gave it a like.

 Respond  
Kirby   -  Apr 14, 2009

Thanks Nem.

 Respond  
Prelude   -  Apr 14, 2009

7/10 kirbz.

 Respond  
Kirby   -  Apr 12, 2009

Firstmate said: > What did Neptune and Imrac give you?
^Neptune said: > Still not sure why I'm in the credits - it's not my image downloading alias at all.
Well, ^Neptune introduced me to this and showed me basics of how to use it. TheImrac was the original maker, though he didn't post the exact version that I have here.

 Respond  
^Neptune   -  Apr 12, 2009

Still not sure why I'm in the credits - it's not my image downloading alias at all.

 Respond  
Firstmate   -  Apr 12, 2009

What did Neptune and Imrac give you?

 Respond  
Aucun50   -  Apr 12, 2009

I love how they don't post why, would be nice to know what to improve on not just say it's crap.

 Respond  
94killerz   -  Apr 12, 2009

Haha, Kris Wilson = Awesomeness.

 Respond  
Aucun50   -  Apr 12, 2009

Nice, thanks for adding the timer helps a lot

 Respond  
Kirby   -  Apr 11, 2009

I gave it a try and it didn't get an error runs smoothly to good job. I think for the attention thing it need more of a timer like 5-7 seconds i didn't even get to read it or maybe it lagged for me not sure.
I think I'll add a timer...perhaps 5 seconds? I've made some updates to the introduction and the code a bit (not sure if you checked it out when you posted).
Echo is now made to the status window too.

 Respond  
Kirby   -  Apr 11, 2009

Made more updates.

Please read the description carefully before you use this.

 Respond  
Aucun50   -  Apr 11, 2009

I gave it a try and it didn't get an error runs smoothly to good job. I think for the attention thing it need more of a timer like 5-7 seconds i didn't even get to read it or maybe it lagged for me not sure.

 Respond  
Aucun50   -  Apr 11, 2009

Interesting, I'll have to try that one out love the idea and what you did with it.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.