changeset 1154:4da4e32b314c

Do not restrict oEmbed support to just video. This will allow us to embed stuff from SoundClound and ReverbNation.
author Brian Neal <bgneal@gmail.com>
date Tue, 27 Dec 2016 10:21:37 -0600
parents be34f981596e
children 0733a0450afe
files oembed/models.py oembed/views.py
diffstat 2 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/oembed/models.py	Tue Dec 27 09:31:08 2016 -0600
+++ b/oembed/models.py	Tue Dec 27 10:21:37 2016 -0600
@@ -37,6 +37,8 @@
         (LINK, "link"),
         (RICH, "rich"),
     )
+    ALLOWED_TYPES = set(choice[1] for choice in MEDIA_TYPE_CHOICES)
+    MEDIA_TYPE_REVERSE = {choice[1]: choice[0] for choice in MEDIA_TYPE_CHOICES}
 
     url = models.URLField(max_length=255, db_index=True)
     type = models.IntegerField(choices=MEDIA_TYPE_CHOICES)
--- a/oembed/views.py	Tue Dec 27 09:31:08 2016 -0600
+++ b/oembed/views.py	Tue Dec 27 10:21:37 2016 -0600
@@ -51,12 +51,13 @@
                 return HttpResponseBadRequest(
                     "Sorry, we could not retrieve your video (%s)" % e)
 
-            if data.get('type') != 'video':
+            data_type = data.get('type', '?')
+            if data_type not in Oembed.ALLOWED_TYPES:
                 return HttpResponseBadRequest(
-                    "Hey, this doesn't look like a video..??")
+                    "Hey, this doesn't look like a media type we support..??")
 
             oembed = Oembed(url=url,
-                            type=Oembed.VIDEO,
+                            type=Oembed.MEDIA_TYPE_REVERSE[data_type],
                             title=data.get('title', ''),
                             width=int(data.get('width', 0)),
                             height=int(data.get('height', 0)),