Skip to content

Commit

Permalink
Make sure the icon pulled is in .ico format.
Browse files Browse the repository at this point in the history
  • Loading branch information
charitarthchugh committed Aug 9, 2023
1 parent 04f6e9f commit f4c48e2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions backend/bookie_backend/bookied/utils/extract-metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ def extract_metadata(url) -> Optional[dict]:
# Get base url
base_url = urllib.parse.urlparse(url).hostname
req = requests.get(f"https://favicongrabber.com/api/grab/{base_url}")
fav_url = req.json()["icons"][0]["src"]
favicon = requests.get(fav_url).content
icons = req.json()["icons"]
for icon in icons:
if icon["src"].endswith(".ico"):
fav_url = icon["src"]
break

if fav_url:
favicon = requests.get(fav_url).content

return {
"title": title.string if title else None,
"description": description["content"] if description else None,
"favicon": favicon if favicon else None,
"favicon_hash": md5(favicon),
"url": url,
}
except Exception as e:
Expand All @@ -44,7 +51,8 @@ def md5(content) -> Optional[str]:
if __name__ == "__main__":
meta = extract_metadata("https://www.youtube.com/watch?v=9bZkp7q19f0")
from pathlib import Path

# save favicon
favicon = meta["favicon"]
if favicon:
print(md5(favicon))
print(md5(favicon))

0 comments on commit f4c48e2

Please sign in to comment.