Files
zulip/zerver/lib/url_preview/oembed/__init__.py
2017-11-04 16:18:27 -07:00

14 lines
400 B
Python

from typing import Optional, Text, Dict
from pyoembed import oEmbed, PyOembedException
def get_oembed_data(url, maxwidth=640, maxheight=480):
# type: (Text, Optional[int], Optional[int]) -> Optional[Dict]
try:
data = oEmbed(url, maxwidth=maxwidth, maxheight=maxheight)
except PyOembedException:
return None
data['image'] = data.get('thumbnail_url')
return data