Image Viewer / Opener

By illhawkthat on Jan 20, 2013

Screenshots

;Image Viewer Script
;Made by nick1
;Last edit March 17 2013

When someone puts an image link in the chat it will open it an mIRC window instead of a browser tab.

Directions: Copy entire code into new remote file. Click on a link to an image and it will open up in a window instead of a browser tab.

Feedback (i.e. comments, questions, concerns, suggestions, jokes, etc.) greatly appreciated.

;Image Viewer Script
;Made by nick1
;Last edit March 17 2013

on $^*:hotlink:/((?:(?:(?:https?)\72\/\/)|(?:www)\.)\S+)(?:(?:jpg|gif|jpeg|png)|(?<=puu\.sh\/)|(?<=my\.jetscreenshot\.com\/)|(?<=imgur\.com\/)(?:\w+))/Sig:*:{
  if ($hotlink(event) == sclick) && (!$sock(getpic)) {
    set %getpic $remove($1,http://,https://)
    ;special link replacement (below) will only work if filetype is JPG
    if ((*puu.sh* iswm %getpic) && (*.* !iswm $remove(%getpic,u.sh))) {
      set %getpic %getpic $+ .jpg
    }
    if ((*imgur.com* iswm %getpic) && (*.* !iswm $remove(%getpic,r.co))) {
      set %getpic $replace($remove(%getpic,/gallery),imgur.com,i.imgur.com) $+ .jpg
    }
    if ((*my.jetscreenshot.com/* iswm %getpic) && (*.* !iswm $remove(%getpic,t.co,y.je))) {
      set %getpic %getpic $+ .jpg
    }
    if (!$file($qt($getdir $+ $gettok(%getpic,-1,47)))) {
      sockopen GetPic $gettok(%getpic,1,47) 80
    }
  }
}
On *:sockopen:getpic:{
  sockwrite -nt $sockname GET $+(/,$gettok(%getpic,2-,47)) HTTP/1.1
  sockwrite -nt $sockname Host: $sock(getpic).addr
  sockwrite -nt $sockname
}
on *:sockread:getpic:{
  if ($sockerr) return
  if (!$sock($sockname).mark) {
    var %SockReader
    sockread %SockReader
    if (%SockReader == $null) { 
      sockmark $sockname 1
      .timerclose $+ $sockname -m 1 3300 imagetimeout
    }
  }
  else {
    sockread -f &picture
    .bwrite $qt($getdir $+ $gettok(%getpic,-1,47)) -1 -1 &picture
  }
}
alias imagetimeout {
  sockclose getpic
  showpic
}
on *:sockclose:getpic: {
  .timerclose $+ $sockname off
  showpic
}
Alias ShowPic {
  var %file $qt($getdir $+ $gettok(%getpic,-1,47))
  var %w $pic(%file).width
  var %h $pic(%file).height
  if (%w == 0) {
    .remove %file
    halt
  }
  else {
    var %win $+(@,$gettok(%getpic,-1,47),-,$chr(40),%w,x,%h,$chr(41))
    window -dCpk0 %win -1 -1 $calc(%w + 17) $calc(%h + 34)
    .timer $+ $gettok(%file,$numtok(%file,32),32) 1 120 .remove %file
    drawpic %win -1 -1 %file
  }
  unset %getpic
}

Comments

Sign in to comment.
WildTiger   -  Dec 17, 2015

wow very cool :D thanks alot !!

illhawkthat  -  Dec 17, 2015

Glad it's helpful!

Sign in to comment

FelicianoX   -  Jan 20, 2013

Oh nice :p

I had something really similar. But if IIRC ON Hotlink was updated and I haven't modified the script yet, so it doesn't work anymore :

Yeah here it is :P : http://www.hawkee.com/snippet/8903/

 Respond  
SReject   -  Jan 20, 2013

A few things I've spotted real quick
1: why is the 7 escaped in your regex @ gopher)\72
2: HTTPS, FTP and gopher, afaik, is a competely different protocol from http, meaning the GET ... Host: headers are invalidly used.
3: Instead of coding the 'redirect' for puu.sh, why not just have your sockets follow redirects?

illhawkthat  -  Jan 20, 2013

Thanks for the feedback @SReject
1 and 2 - I'm not sure because I didn't make the regex string. (thanks to Wiz126 #msl swiftirc for it) - I will look into changing it to better fit this script in the future. (Also I don't really see people link to FTP or Gopher images so they seem useless haha)

  1. it's not a 301 redirect. the puu.sh links ARE direct image links but they don't have a file extension. I added a comment to show this.

I made some edits to the code above.

Conscious  -  Jan 21, 2013

\72 is octal for :

SReject  -  Jan 21, 2013

I didn't really test it, but i think this would be a far better regex:

/(?:http:\/\/)?(?:www\.)?(|(\S+\.(?:jpe?g|gif|png))|(puu\.sh\/\w+))/Sig

@Conscious after I commented, I remember

illhawkthat  -  Jan 21, 2013

@SReject It works for https links. What are you doing? I also thinkit would work for FTP links. I don't know shit about gopher.
Appreciate it though. Can you add imgur in there? (I'm shit with regex).

SReject  -  Jan 21, 2013

@illhawkthat It doesn't work for https or ftp links. It is basically converting the URL to a HTTP link. Some/Most servers support an HTTP fall back for HTTPS links.

illhawkthat  -  Jan 21, 2013

I know. That's why I strip the HTTPS - for direct image links I think the server almost always accepts HTTP

    set %getpic $remove($1,http://,https://)
SReject  -  Jan 21, 2013

Sorry if I keep coming off sounding arrogant, it's not my intention. If you wanted true HTTPS(not sure, but I think FTP aswell) support, you could use one of these inplace of your sockets:

Call back style downloading of a file:
http://www.hawkee.com/snippet/9318/

Semi-blocking downloading of a file:
http://www.hawkee.com/snippet/8993/

illhawkthat  -  Jan 21, 2013

No not at all arrogant! I appreciate the comments!! I don't really feel like replacing this though. I made it about a year ago just because it was annyoing me people kept linking images.

But for now it works on all the images I have tried. Thanks though!!

Conscious  -  Jan 21, 2013

SSL sockets could be made using sockopen -e

And @SReject is right, HTTP protocol does not work with FTP, lol

illhawkthat  -  Jan 21, 2013

Thanks @Conscious I'll put up a new regex string within the week when I can find someone to make one for me haha. I appreciate all the feedback!

Sign in to comment

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.