2018-05-10 19:13:36 +02:00
|
|
|
from typing import Optional, Dict, Any
|
2016-10-27 12:06:44 +02:00
|
|
|
from pyoembed import oEmbed, PyOembedException
|
|
|
|
|
|
|
|
|
2018-05-10 19:13:36 +02:00
|
|
|
def get_oembed_data(url: str,
|
2017-11-05 11:15:10 +01:00
|
|
|
maxwidth: Optional[int]=640,
|
2018-06-16 23:00:17 +02:00
|
|
|
maxheight: Optional[int]=480) -> Optional[Dict[str, 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
|