def get_thumbnail(url, width, height): try: return OembedlyCache.objects.filter(url=url, width=width, height=height)[0].thumbnail except IndexError: try: result = get_oembed(url, format='json', maxwidth=width, maxheight=height) thumbnail = result['thumbnail_url'] code = result['html'] except KeyError: return False except Exception, e: return False obj = OembedlyCache(url=url, width=width, height=height, thumbnail=thumbnail, code=code) obj.save() return thumbnail
def get_code(url, width, height): try: return OembedlyCache.objects.filter(url=url, width=width, height=height)[0].code except IndexError: try: result = get_oembed(url, format='json', maxwidth=width, maxheight=height) thumbnail = result['thumbnail_url'] code = result['html'] except KeyError: return 'Unable to embed code for video <a href="%s">%s</a>' % (url, url) except Exception, e: return 'Unable to embed code for video <a href="%s">%s</a><br>Error: %s' % (url, url, e) obj = OembedlyCache(url=url, width=width, height=height, code=code, thumbnail=thumbnail) obj.save() return code