Mercurial > public > sg101
changeset 361:6d6fdc58487c
Changes to oembed to support vimeo.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 Mar 2011 03:23:29 +0000 |
parents | 2e90b63520b8 |
children | c5ae0a276e33 |
files | gpp/oembed/core.py gpp/oembed/views.py gpp/settings.py |
diffstat | 3 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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)
--- 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 #######################################################################