Imgur URL Recogniser

By ES on Jan 20, 2014

When it recognises a imgur link in the chat, it automatically posts info about that link if it's available.

It will post the following information:
Title
Description (In the case of albums)
Number of images (In the case of albums)
Number of views
Time uploaded
A NSFW tag (If it was tagged as such)

Image

http://imgur.com/a/y79xB?gallery <@ES> imgur » Famous Movie Locations (Part 1) · Album: 28 images · Uploaded: 1 day ago · 312,096 views

Image

on $*:TEXT:/((https?[\S]*imgur\.com[\S]*))/Si:#: {
  if (!$sock(ImgurLookup)) {
    noop $regex(imgururl,$1-,(https?[\S]*imgur\.com[\S]*))
    sockopen ImgurLookup imgur.com 80 | sockmark ImgurLookup $+(#,>,$gettok($gettok($regml(imgururl,1),3-,47),1,46))
  }
}
on *:sockopen:ImgurLookup: {
  var %a sockwrite -n $sockname
  %a GET $+(/,$gettok($sock(ImgurLookup).mark,2,62)) HTTP/1.1
  %a Host: imgur.com
  %a $crlf
}
on *:sockread:ImgurLookup: {
  var %x | sockread %x
  if ($left($gettok($soc`k(ImgurLookup).mark,2,62),2) == a/) { 
    if (</title> isin %x) { set %z 1 | sockmark ImgurLookup $addmark(ImgurLookup,$remove($Xchr($nohtml(%x)),- Imgur),62) }
    if (<p> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$Xchr($nohtml(%x)),62) }
    if (class="textbox left"> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$remove($Xchr($nohtml(%x)),Album:),62) }
    if (GMT"> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$Xchr($nohtml(%x)),62) }
    if (class="stat"> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$Xchr($nohtml(%x)),62) }    
  }
  else {
    if ("hash" isin %x) { 
      noop $regex(imgurtitle,%x,("title":".*?,))
      noop $regex(imgurviews,%x,("views"[\S]*,))
      noop $regex(imgurnsfw,%x,("nsfw"[\S]*,))
      noop $regex(imgurtime,%x,("timestamp"[\S]*\s[\S]*,)|("datetime"[\S]*\s[\S]*,))
      if ($remove($between($regml(imgurtitle,1),$chr(58),$chr(44),1),") == $null) { halt }
      else {
        msg $gettok($sock(ImgurLookup).mark,1,62) 9,1i0,1mgur » $+(",$remove($between($regml(imgurtitle,1),$chr(58),$chr(44),1),"),") $iif($between($regml(imgurviews,1),$chr(58),$chr(44),1),9· $remove($between($regml(imgurviews,1),$chr(58),$chr(44),1),") Views) $iif($remove($between($regml(imgurtime,1),$chr(58),$chr(44),1),"),9· Uploaded: $timeago($calc($timezone + $ctime - $ctime($remove($between($regml(imgurtime,1),$chr(58),$chr(44),1),"))))) $iif($between($regml(imgurnsfw,1),$chr(58),$chr(44),1) == true,9· 4NSFW)
      }
    }
  }
}

on *:sockclose:ImgurLookup: {
  if (%z == 1) { 
    if ($left($gettok($sock(ImgurLookup).mark,2,62),2) == a/) { 
      if ($numtok($sock(ImgurLookup).mark,62) == 6) { sockmark ImgurLookup $instok($sock(ImgurLookup).mark,fillertext,5,62) }
      msg $gettok($sock(ImgurLookup).mark,1,62) 9,1i0,1mgur 9» $gettok($sock(ImgurLookup).mark,3,62) $iif($gettok($sock(ImgurLookup).mark,5,62) != fillertext,$+($chr(40),$gettok($sock(ImgurLookup).mark,5,62),$chr(41))) 9· Album: $gettok($sock(ImgurLookup).mark,4,62) 9· $iif($gettok($sock(ImgurLookup).mark,6,62),Uploaded: $gettok($sock(ImgurLookup).mark,6,62)) 9· $iif($gettok($sock(ImgurLookup).mark,7,62),$gettok($sock(ImgurLookup).mark,7,62))
    }
  }
  unset %z
}

alias -l nohtml { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;) | return %x }
alias -l Xchr { 
  var %return $regsubex($regsubex($1-,/&#x([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1)) 
  return $replacecs(%return,&ndash;,,&middot;,·,&raquo;,»,&laquo;,«,&Uuml;,Ü,&uuml;,ü,&Aacute;,Á,&aacute;,á,&Eacute;,$&
    É,&eacute;,é,&Iacute;,Í,&iacute;,í,&Oacute;,Ó,&oacute;,ó,&Ntilde;,Ñ,&ntilde;,ñ,&Uacute;,Ú,&uacute;,ú,&nbsp;,$chr(32),$&
    &aelig;,æ,&quot;,",&amp;,&,&#039;,')
}
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 timeago {
  if ($1 <= 59) { Return $1 seconds ago }
  if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) minutes ago }
  if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) hours ago }
  if (($1 <= 2592000) && ($1 > 86399)) { return $floor($calc($1 / 86400)) $iif($floor($calc($1 / 86400)) > 1,days,day) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 86400))*86400)) / 3600),0) hour(s) ago }
  if (($1 <= 31540000) && ($1 > 2592000)) { return $floor($calc($1 / 2592000)) $iif($floor($calc($1 / 2592000)) > 1,months,months) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 2592000))*2592000)) / 86400),0) day(s) ago }
  if ($1 > 31104000) { return $floor($calc($1 / 31104000)) $iif($floor($calc($1 / 31104000)) > 1,years,year) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 31104000))*31104000)) / 2592000),0) month(s) ago }
}

Comments

Sign in to comment.
dma   -  Nov 27, 2015

can someone fix this please?

 Respond  
Erroneus   -  Sep 17, 2015

Update
Not happening anymore, might have been a problem at IMGUR.

I'm getting double results, any idea why?

[22:37:10] <@Erroneus> https://i.imgur.com/27nm1DF.png
[22:37:10] <@BOT> imgur » "Rise and BURP shine..." · 5233 Views · Uploaded: 7 hours ago
[22:37:10] <@BOT> imgur » "Rise and BURP shine..." · 5233 Views · Uploaded: 7 hours ago

Erroneus  -  Oct 02, 2015

Strange, still seeing this.

Looks like it's happening on PNG and GIFV links, but not JPG's.

Erroneus  -  Oct 14, 2015

Getting really trippy responses

eg.
[11:31:38] <@Erroneus> https://i.imgur.com/cUPs4dD.jpg
[11:31:40] <@BOT> imgur » "Welcome to Imgur!"
[11:31:40] <@BOT>> imgur » "Was playing a game on my phone when it said this." · 4306 Views · Uploaded: 17 hours ago
[11:31:40] <@BOT>> imgur » "Was playing a game on my phone when it said this." · 4306 Views · Uploaded: 17 hours ago

dma  -  Dec 13, 2015

mine sometimes never shows

Sign in to comment

ovelayer   -  Nov 22, 2014

great work ty

 Respond  
Adjust   -  May 21, 2014

I can't get this to work as of 22 May 2014
mIRC v 7.32
Edit: It does seem to work except for the person running the script (it will work for other users) can that be changed please

hxck  -  Jun 08, 2014

You can't trigger on :*TEXT: snippets from the client they run on. This snippet is intended for a bot client. Add this to the snippet if you want to run it on your main client:

on *:INPUT:#:{
  if (!$sock(ImgurLookup)) {
    noop $regex(imgururl,$1-,(https?[\S]*imgur\.com[\S]*))
    sockopen ImgurLookup imgur.com 80 | sockmark ImgurLookup $+(#,>,$gettok($gettok($regml(imgururl,1),3-,47),1,46))
  }
}
Sign in to comment

Angeris   -  Mar 14, 2014

Hello there,i really like this one,and i was looking for something that would show me imgur titles. Thing is that i only need it for a couple of channels where i don't have op status so i want to ask you a favor if you could tweak this somehow, show only title and nsfw tag ,no colors and if i could activate it in certain channels somehow, some channels don't like announces like this. PS it should announce my links too, cause i will load it in my client and not in some bot. Thanks in advance.

 Respond  
MashhitDK   -  Feb 22, 2014

Not tested... but nicely nicely... I like the idea...
might "rip" your work later on and implement it to My URL fetcher

 Respond  
nox`   -  Jan 21, 2014

Http://imgur.com/a/y79xB?gallery
Http://imgur.com/a/y79xB
Http://i.imgur.com/uR68H.jpg
http://imgur.com/uR68H
I do not know if there are other valid formats

on $*:TEXT:$($imgreg):#: {
  if (!$sock(ImgurLookup)) {
    sockopen ImgurLookup imgur.com 80 | sockmark ImgurLookup $+(#,$chr(32),$regml(1))
  }
}
alias imgreg return /https?\72\/\/(?:i\.)?imgur\.com\/((?:a\/)?[a-z\d]+)/Si
on *:sockopen:ImgurLookup:{
  var %a sockwrite -n $sockname
  %a GET $+(/,$gettok($sock(ImgurLookup).mark,2,32)) HTTP/1.1
  %a Host: imgur.com
  %a $crlf
}
on *:sockread:ImgurLookup:{
  var %x
  sockread %x
  if $regex(%x,/([^>]+)<\/title>/) { set %ImgurLookuptitle $gettok($regml(1),-2,45) }
  if $regex(%x,<h2 class="textbox left">([^>]+)<\/h2>) { set %ImgurLookupalbum · $regml(1) }
  if $regex(%x,<span title=".+ GMT">([^>]+)<\/span>) { set %ImgurLookupage $regml(1) }
  if $regex(%x,<span (?:class|id)="stat(?:s-views)?">([^>]+)<\/span>) { set %ImgurLookupview $regml(1) }
  if "nsfw":true isincs %x { set %ImgurLookupnsfw 9· 4NSFW }
  if $regex(%x,"datetime":"([^"]+)") && !%ImgurLookupage { set %ImgurLookupage $timeago($calc($ctime - $ctime($regml(1)))) }
}
on *:sockclose:ImgurLookup: {
  msg $gettok($sock(ImgurLookup).mark,1,32) 9,1i0,1mgur » %ImgurLookuptitle %ImgurLookupalbum · Uploaded: %ImgurLookupage · %ImgurLookupview views %ImgurLookupnsfw
  unset %ImgurLookup*
}
alias timeago {
  if ($1 <= 59) { Return $1 seconds ago }
  if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) minutes ago }
  if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) hours ago }
  if (($1 <= 2592000) && ($1 > 86399)) { return $floor($calc($1 / 86400)) $iif($floor($calc($1 / 86400)) > 1,days,day) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 86400))*86400)) / 3600),0) hour(s) ago }
  if (($1 <= 31540000) && ($1 > 2592000)) { return $floor($calc($1 / 2592000)) $iif($floor($calc($1 / 2592000)) > 1,months,months) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 2592000))*2592000)) / 86400),0) day(s) ago }
  if ($1 > 31104000) { return $floor($calc($1 / 31104000)) $iif($floor($calc($1 / 31104000)) > 1,years,year) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 31104000))*31104000)) / 2592000),0) month(s) ago }
}
ES  -  Jan 24, 2014

Neat. I'm not all that great with regex.

Sign in to comment

hxck   -  Jan 20, 2014

Nice job man.

 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.