Skip to content

Instantly share code, notes, and snippets.

@artgibson
Forked from embedly/embedly_oembed.py
Created August 3, 2010 14:55
Show Gist options
  • Save artgibson/506505 to your computer and use it in GitHub Desktop.
Save artgibson/506505 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib
import urllib2
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
raise ImportError("Need a json decoder")
ACCEPTED_ARGS = ['maxwidth', 'maxheight', 'format']
def get_oembed(url, **kwargs):
"""
Example Embedly oEmbed Function
"""
api_url = 'http://api.embed.ly/1/oembed?'
params = {'url':url }
for key, value in kwargs.items():
if key not in ACCEPTED_ARGS:
raise ValueError("Invalid Argument %s" % key)
params[key] = value
oembed_call = "%s%s" % (api_url, urllib.urlencode(params))
return json.loads(urllib2.urlopen(oembed_call).read())
if __name__ == "__main__":
urls = ["http://vimeo.com/9503416",
"http://plixi.com/p/12870944"]
for url in urls:
print "\n\nurl: %s\n" % url
print get_oembed(url)
print "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment