2017-11-05 17:22:51 +01:00
|
|
|
from typing import Optional, Text, Dict, Any
|
2016-10-27 12:06:44 +02:00
|
|
|
from pyoembed import oEmbed, PyOembedException
|
|
|
|
|
|
|
|
|
|
|
|
def get_oembed_data(url, maxwidth=640, maxheight=480):
|
2017-11-05 17:22:51 +01:00
|
|
|
# type: (Text, Optional[int], Optional[int]) -> Optional[Dict[Any, Any]]
|
2016-10-27 12:06:44 +02:00
|
|
|
try:
|
|
|
|
data = oEmbed(url, maxwidth=maxwidth, maxheight=maxheight)
|
|
|
|
except PyOembedException:
|
|
|
|
return None
|
|
|
|
|
|
|
|
data['image'] = data.get('thumbnail_url')
|
|
|
|
return data
|