Mercurial > public > sg101
comparison oembed/views.py @ 909:90632d090bbc
Merge with upstream.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 16 Mar 2015 21:03:37 -0500 |
parents | 344f7914d421 |
children | 4da4e32b314c |
comparison
equal
deleted
inserted
replaced
902:4dee923a2f6d | 909:90632d090bbc |
---|---|
41 providers = Provider.objects.all() | 41 providers = Provider.objects.all() |
42 for provider in providers: | 42 for provider in providers: |
43 if re.match(provider.url_regex, url): | 43 if re.match(provider.url_regex, url): |
44 try: | 44 try: |
45 data = get_oembed(provider.api_endpoint, | 45 data = get_oembed(provider.api_endpoint, |
46 url, | 46 url, |
47 maxwidth=settings.OEMBED_MAXWIDTH, | 47 maxwidth=settings.OEMBED_MAXWIDTH, |
48 maxheight=settings.OEMBED_MAXHEIGHT) | 48 maxheight=settings.OEMBED_MAXHEIGHT, |
49 scheme='https') | |
49 except IOError, e: | 50 except IOError, e: |
50 return HttpResponseBadRequest( | 51 return HttpResponseBadRequest( |
51 "Sorry, we could not retrieve your video (%s)" % e) | 52 "Sorry, we could not retrieve your video (%s)" % e) |
52 | 53 |
53 if 'type' not in data or data['type'] != 'video': | 54 if data.get('type') != 'video': |
54 return HttpResponseBadRequest( | 55 return HttpResponseBadRequest( |
55 "Hey, this doesn't look like a video..??") | 56 "Hey, this doesn't look like a video..??") |
56 | 57 |
57 oembed = Oembed(url=url, | 58 oembed = Oembed(url=url, |
58 type=Oembed.VIDEO, | 59 type=Oembed.VIDEO, |
59 title=data.get('title', ''), | 60 title=data.get('title', ''), |
60 width=int(data.get('width', 0)), | 61 width=int(data.get('width', 0)), |
61 height=int(data.get('height', 0)), | 62 height=int(data.get('height', 0)), |
62 html=data.get('html', '')) | 63 html=data.get('html', '')) |
63 oembed.save() | 64 oembed.save() |
64 | 65 |
65 data = dict(id=oembed.id, embed=oembed.html) | 66 data = dict(id=oembed.id, embed=oembed.html) |
66 return HttpResponse(json.dumps(data), | 67 return HttpResponse(json.dumps(data), |
67 content_type='application/json') | 68 content_type='application/json') |