nox` commented on a Page, Imgur URL Recogniser  -  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

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.