fixed vimeo oembed

This commit is contained in:
mdipierro
2012-08-19 18:36:18 -05:00
parent 531f592e3b
commit bb0fcc85d6
2 changed files with 12 additions and 5 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-08-19 18:20:11) dev
Version 2.00.0 (2012-08-19 18:36:14) dev
+11 -4
View File
@@ -126,12 +126,19 @@ EXTENSION_MAPS = {
'xps': googledoc_viewer,
}
class VimeoURLOpener(urllib.FancyURLopener):
"Vimeo blocks the urllib user agent for some reason"
version = "Mozilla/4.0"
urllib._urlopener = VimeoURLOpener()
def oembed(url):
for k,v in EMBED_MAPS:
if k.match(url):
oembed = v+'?format=json&url='+cgi.escape(url)
try:
return loads(urllib.urlopen(oembed).read())
try:
data = urllib.urlopen(oembed).read()
print data
return loads(data) # json!
except:
pass
return {}
@@ -143,10 +150,10 @@ def expand_one(url,cdict):
# try ombed but first check in cache
if cdict and url in cdict:
r = cdict[url]
elif cdict:
r = cdict[url] = oembed(url)
else:
r = oembed(url)
if isinstance(cdict,dict):
cdict[url] = r
# if oembed service
if 'html' in r:
html = r['html'].encode('utf8')