Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
instance.image_url = instance.image.url
instance.file_name = os.path.basename(str(instance.image_url))
if not instance.name:
instance.name = instance.file_name
instance.thumbnail_image = instance.image
if instance.thumbnail_image:
instance.thumbnail_image_url = instance.thumbnail_image.url
instance.save()
if instance.video_url:
try:
import micawber
providers = micawber.bootstrap_basic()
oembed = providers.request(instance.video_url)
if "html" in oembed:
instance.video_embed = oembed["html"]
if not instance.thumbnail_image:
if "thumbnail_url" in oembed:
instance.thumbnail_image_url = oembed["thumbnail_url"]
if "thumbnail_width" in oembed:
instance.thumbnail_image_height = oembed["thumbnail_width"]
if "thumbnail_height" in oembed:
instance.thumbnail_image_height = oembed["thumbnail_height"]
except Exception as e:
print traceback.format_exc()
#Process images and thumbnails
def save(self, *args, **kwargs):
providers = micawber.bootstrap_basic()
try:
self.embed = providers.request(self.link)['html']
except micawber.ProviderException,e:
self.embed = None
super(Link,self).save(*args, **kwargs)
def _build_provider_list():
"""
Construct the provider registry, using the app settings.
"""
registry = None
if appsettings.FLUENT_OEMBED_SOURCE == "basic":
registry = bootstrap_basic()
elif appsettings.FLUENT_OEMBED_SOURCE == "embedly":
params = {}
if appsettings.MICAWBER_EMBEDLY_KEY:
params["key"] = appsettings.MICAWBER_EMBEDLY_KEY
registry = bootstrap_embedly(**params)
elif appsettings.FLUENT_OEMBED_SOURCE == "noembed":
registry = bootstrap_noembed(nowrap=1)
elif appsettings.FLUENT_OEMBED_SOURCE == "list":
# Fill list manually in the settings, e.g. to have a fixed set of supported secure providers.
registry = ProviderRegistry()
for regex, provider in appsettings.FLUENT_OEMBED_PROVIDER_LIST:
registry.register(regex, Provider(provider))
else:
raise ImproperlyConfigured(
"Invalid value of FLUENT_OEMBED_SOURCE, only 'basic', 'list', 'noembed' or 'embedly' is supported."
)
def bootstrap(cache=None):
# micawbers own bootstrap basic plus some more
pr = bootstrap_basic(cache=cache)
# add https support for vimeo and youtube
pr.register('https://vimeo.com/\S*', Provider('https://vimeo.com/api/oembed.json'))
try:
pr.unregister('https?://(\S*.)?youtu(\.be/|be\.com/watch)\S+')
except KeyError: # if not registered
pass
pr.register('https?://(\S*.)?youtu(\.be/|be\.com/watch)\S+', Provider('https://www.youtube.com/oembed?scheme=https'))
return pr