2016-10-27 12:06:44 +02:00
|
|
|
from __future__ import absolute_import
|
2016-12-21 13:17:53 +01:00
|
|
|
from typing import Optional, Any, Text
|
2016-10-27 12:06:44 +02:00
|
|
|
from pyoembed import oEmbed, PyOembedException
|
|
|
|
|
|
|
|
|
|
|
|
def get_oembed_data(url, maxwidth=640, maxheight=480):
|
2016-12-21 13:17:53 +01:00
|
|
|
# type: (Text, Optional[int], Optional[int]) -> 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
|