Skip to content

Commit

Permalink
title: pick longest title if there are multiple ones
Browse files Browse the repository at this point in the history
  • Loading branch information
pbui committed Feb 24, 2024
1 parent eb01904 commit ccec8cd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/bobbit/modules/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async def title(bot, message, url=None, override=False):
(response := await photon_title(bot, url, text, message)) or
(response := await youtube_title(bot, url, text))
):
html_title = re.findall(r'<title[^>]*>([^<]+)</title>', text)[0]
# XXX: If there are multiple titles, take the longest one (ugly workaround)
html_title = sorted(re.findall(r'<title[^>]*>([^<]+)</title>', text), key=len)[-1]
response = bot.client.format_text(
'{color}{green}Title{color}: {bold}{title}{bold}',
title = strip_html(html.unescape(html_title)).strip()
Expand Down

0 comments on commit ccec8cd

Please sign in to comment.