changeset 907:344f7914d421

Add scheme=https to oembed request. YouTube added this so you could get HTML that used https to embed the video. It seems that Vimeo also supports it.
author Brian Neal <bgneal@gmail.com>
date Sun, 15 Mar 2015 21:48:33 -0500
parents be233ba7ca31
children 2181da65c98b
files oembed/core.py oembed/views.py
diffstat 2 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/oembed/core.py	Sun Mar 08 11:06:07 2015 -0500
+++ b/oembed/core.py	Sun Mar 15 21:48:33 2015 -0500
@@ -52,6 +52,7 @@
 if __name__ == "__main__":
     try:
         print get_oembed("http://www.youtube.com/oembed",
-                "http://www.youtube.com/watch?v=7_IMzJldOf4")
+                         "http://www.youtube.com/watch?v=7_IMzJldOf4",
+                         scheme='https')
     except urllib2.HTTPError, e:
         print e
--- a/oembed/views.py	Sun Mar 08 11:06:07 2015 -0500
+++ b/oembed/views.py	Sun Mar 15 21:48:33 2015 -0500
@@ -43,23 +43,24 @@
         if re.match(provider.url_regex, url):
             try:
                 data = get_oembed(provider.api_endpoint,
-                        url,
-                        maxwidth=settings.OEMBED_MAXWIDTH,
-                        maxheight=settings.OEMBED_MAXHEIGHT)
+                                  url,
+                                  maxwidth=settings.OEMBED_MAXWIDTH,
+                                  maxheight=settings.OEMBED_MAXHEIGHT,
+                                  scheme='https')
             except IOError, e:
                 return HttpResponseBadRequest(
                     "Sorry, we could not retrieve your video (%s)" % e)
 
-            if 'type' not in data or data['type'] != 'video':
+            if data.get('type') != 'video':
                 return HttpResponseBadRequest(
                     "Hey, this doesn't look like a video..??")
 
             oembed = Oembed(url=url,
-                    type=Oembed.VIDEO,
-                    title=data.get('title', ''),
-                    width=int(data.get('width', 0)),
-                    height=int(data.get('height', 0)),
-                    html=data.get('html', ''))
+                            type=Oembed.VIDEO,
+                            title=data.get('title', ''),
+                            width=int(data.get('width', 0)),
+                            height=int(data.get('height', 0)),
+                            html=data.get('html', ''))
             oembed.save()
 
             data = dict(id=oembed.id, embed=oembed.html)