Skip to content

Commit

Permalink
[title] Fix !title not working with YT and add unescaping of HTML ent…
Browse files Browse the repository at this point in the history
…ites
  • Loading branch information
sfan5 committed Aug 6, 2015
1 parent b39ebb0 commit 29b8686
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions title.py
Expand Up @@ -6,19 +6,19 @@

import re
import web
import html

r_title = re.compile(r'(?ims)<\s*title[^>]*>(.*?)<\s*/\s*title\s*>')

def title(phenny, input):
uri = input.group(2)
if uri:
pass
uri = uri.strip()
elif hasattr(phenny.bot, 'last_seen_uri'):
uri = phenny.bot.last_seen_uri
else:
return phenny.reply("Give me an URI..")
uri = uri.strip()
data, sc = web.get(uri, 4096)
data, sc = web.get(uri, 16384)
if sc != 200:
return phenny.say("HTTP error %d" % sc)
try:
Expand All @@ -28,7 +28,9 @@ def title(phenny, input):
m = re.search(r_title, data)
if not m:
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:
title = title[:150] + "[...]"
phenny.reply(title)
Expand Down

0 comments on commit 29b8686

Please sign in to comment.