Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
#1395 added updates to fix embed code error
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbixly committed Jan 21, 2015
1 parent fc97195 commit ca26f94
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion videos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,30 @@ def get_thumbnail(url, width, height):
@staticmethod
def get_code(url, width, height):
try:
return OembedlyCache.objects.filter(url=url, width=width, height=height)[0].code
instance = OembedlyCache.objects.filter(url=url, width=width, height=height)[0]
code = instance.code
# find and replace https: with blank for embed to become protocol independent
if 'https:' in code:
code.replace('https:', '')

elif 'http:' in code:
code.replace('http:', '')

instance.code = code
instance.save()
return code

except IndexError:
try:
result = client.oembed(url, format='json', maxwidth=width, maxheight=height)
thumbnail = result['thumbnail_url']
code = result['html']
if 'https:' in code:
code.replace('https:', '')

if 'http:' in code:
code.replace('http:', '')

except KeyError:
return 'Unable to embed code for <a href="%s">%s</a>' % (url, url)
except Exception, e:
Expand Down

0 comments on commit ca26f94

Please sign in to comment.