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
|
|
|
|
|
|
|
|
|
2017-11-05 11:15:10 +01:00
|
|
|
def get_oembed_data(url: Text,
|
|
|
|
maxwidth: Optional[int]=640,
|
|
|
|
maxheight: Optional[int]=480) -> 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
|