Url: Use og:title meta property if found. Fixes #90.

This commit is contained in:
Ville Ranki 2020-07-13 23:06:55 +03:00
parent 69c18070f7
commit 11f2917d49
1 changed files with 5 additions and 1 deletions

View File

@ -114,7 +114,11 @@ class MatrixModule(BotModule):
# try parse and get the title
try:
soup = BeautifulSoup(r.text, "html.parser")
if soup.head and soup.head.title:
# Prefer og:title first (for example Youtube uses this)
ogtitle = soup.find("meta", property="og:title")
if ogtitle:
title = ogtitle["content"]
elif soup.head and soup.head.title:
title = soup.head.title.string.strip()
descr_tag = soup.find("meta", attrs={"name": "description"})
if descr_tag: