Allow titling all content types, refine size display
This commit is contained in:
parent
640e3fd3a9
commit
b07a6202b4
|
@ -96,12 +96,19 @@ class LinkTitler(ModuleBase):
|
|||
title = self.url_htmltitle(match[0])
|
||||
if title:
|
||||
self.bot.act_PRIVMSG(args[0], "%s: \x02%s\x02" % (sender.nick, title))
|
||||
|
||||
if "image/" in headers["Content-Type"]:
|
||||
self.bot.act_PRIVMSG(args[0], "%s: \x02%s\x02, %s" % (sender.nick, headers["Content-Type"], str(int(int(headers["Content-Length"])/1024))+"KB" if "Content-Length" in headers else "unknown size"))
|
||||
else:
|
||||
# Unknown types, just print type and size
|
||||
self.bot.act_PRIVMSG(args[0], "%s: \x02%s\x02, %s" % (sender.nick, headers["Content-Type"], self.nicesize(int(headers["Content-Length"])) if "Content-Length" in headers else "unknown size"))
|
||||
|
||||
return
|
||||
|
||||
def nicesize(self, numBytes):
|
||||
"Return kb or plain bytes"
|
||||
if numBytes > 1024:
|
||||
return "%skb" % str(int(numBytes/1024))
|
||||
else:
|
||||
return "<1kb"
|
||||
|
||||
def url_headers(self, url):
|
||||
"HEAD requests a url to check content type & length, returns something like: {'type': 'image/jpeg', 'size': '90583'}"
|
||||
self.log.debug("url_headers(%s)" % (url,))
|
||||
|
@ -121,7 +128,7 @@ class LinkTitler(ModuleBase):
|
|||
break
|
||||
|
||||
titleMatches = re.findall(r'<title>([^<]+)</title>', data, re.I)
|
||||
if len(titleMatches)>0 and resp.status_code==200:
|
||||
if len(titleMatches)>0:# and resp.status_code==200:
|
||||
h = html.parser.HTMLParser()
|
||||
title = h.unescape(titleMatches[0]).strip()
|
||||
if len(title)>0:
|
||||
|
|
Loading…
Reference in New Issue