# HG changeset patch # User Brian Neal # Date 1299295409 0 # Node ID 6d6fdc58487c1a53ee14db5127e69932c529dbe9 # Parent 2e90b63520b854ca5993d132609bca518d4d7266 Changes to oembed to support vimeo. diff -r 2e90b63520b8 -r 6d6fdc58487c gpp/oembed/core.py --- a/gpp/oembed/core.py Sat Mar 05 02:30:53 2011 +0000 +++ b/gpp/oembed/core.py Sat Mar 05 03:23:29 2011 +0000 @@ -31,7 +31,7 @@ api_url = "%s?%s" % (api_endpoint, urllib.urlencode(opts)) headers = { - 'User-Agent': USER_AGENT, + 'User-Agent': USER_AGENT, 'Accept-Encoding': 'gzip', } request = urllib2.Request(api_url, headers=headers) @@ -43,15 +43,15 @@ f.close() if headers.get('content-encoding') == 'gzip': - with gzip.GzipFile(fileobj=StringIO(result)) as f: - result = f.read() + f = gzip.GzipFile(fileobj=StringIO(result)) + result = f.read() + f.close() return json.loads(result) 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=99999999999") + "http://www.youtube.com/watch?v=7_IMzJldOf4") except urllib2.HTTPError, e: print e diff -r 2e90b63520b8 -r 6d6fdc58487c gpp/oembed/views.py --- a/gpp/oembed/views.py Sat Mar 05 02:30:53 2011 +0000 +++ b/gpp/oembed/views.py Sat Mar 05 03:23:29 2011 +0000 @@ -8,6 +8,7 @@ from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden import django.utils.simplejson as json +from django.conf import settings from oembed.models import Provider from oembed.models import Oembed @@ -41,7 +42,10 @@ for provider in providers: if re.match(provider.url_regex, url): try: - data = get_oembed(provider.api_endpoint, url) + data = get_oembed(provider.api_endpoint, + url, + maxwidth=settings.OEMBED_MAXWIDTH, + maxheight=settings.OEMBED_MAXHEIGHT) except IOError, e: return HttpResponseBadRequest( "Sorry, we could not retrieve your video (%s)" % e) diff -r 2e90b63520b8 -r 6d6fdc58487c gpp/settings.py --- a/gpp/settings.py Sat Mar 05 02:30:53 2011 +0000 +++ b/gpp/settings.py Sat Mar 05 03:23:29 2011 +0000 @@ -247,6 +247,10 @@ MAILER_ENQUEUE_MAIL = True +# Oembed settings +OEMBED_MAXWIDTH = 480 +OEMBED_MAXHEIGHT = 295 + ####################################################################### # Configure Logging #######################################################################