[title] Fix !title not working with YT and add unescaping of HTML entites

master
sfan5 2015-08-06 12:01:32 +02:00
parent b39ebb013b
commit 29b86866f6
1 changed files with 6 additions and 4 deletions

View File

@ -6,19 +6,19 @@ Copyright 2014, sfan5
import re import re
import web import web
import html
r_title = re.compile(r'(?ims)<\s*title[^>]*>(.*?)<\s*/\s*title\s*>') r_title = re.compile(r'(?ims)<\s*title[^>]*>(.*?)<\s*/\s*title\s*>')
def title(phenny, input): def title(phenny, input):
uri = input.group(2) uri = input.group(2)
if uri: if uri:
pass uri = uri.strip()
elif hasattr(phenny.bot, 'last_seen_uri'): elif hasattr(phenny.bot, 'last_seen_uri'):
uri = phenny.bot.last_seen_uri uri = phenny.bot.last_seen_uri
else: else:
return phenny.reply("Give me an URI..") return phenny.reply("Give me an URI..")
uri = uri.strip() data, sc = web.get(uri, 16384)
data, sc = web.get(uri, 4096)
if sc != 200: if sc != 200:
return phenny.say("HTTP error %d" % sc) return phenny.say("HTTP error %d" % sc)
try: try:
@ -28,7 +28,9 @@ def title(phenny, input):
m = re.search(r_title, data) m = re.search(r_title, data)
if not m: if not m:
return phenny.say("No title found.") return phenny.say("No title found.")
title = m.group(1).strip() title = m.group(1)
title = html.unescape(title)
title = title.strip()
if len(title) > 150: if len(title) > 150:
title = title[:150] + "[...]" title = title[:150] + "[...]"
phenny.reply(title) phenny.reply(title)