comparison oembed/views.py @ 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 89b240fe9297
children 4da4e32b314c
comparison
equal deleted inserted replaced
905:be233ba7ca31 907:344f7914d421
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')