Created
December 19, 2013 20:52
-
-
Save nicksnell/8046084 to your computer and use it in GitHub Desktop.
Fetches a thumbnail URL for a given video (and size) from Vimeo metadata API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import urllib2 | |
| def get_vimeo_thumbnail(vimeo_video_id, size='large'): | |
| """Fetches a thumbnail URL for a given video (and size) from Vimeo metadata API""" | |
| assert size in ['small', 'medium', 'large'], 'You must specify a valid size! small/medium/large' | |
| req = urllib2.urlopen('http://vimeo.com/api/v2/video/%s.json' % vimeo_video_id) | |
| try: | |
| data = json.loads(req.read())[0] | |
| except (ValueError, IndexError): | |
| return None | |
| key = 'thumbnail_%s' % size | |
| if not key in data: | |
| return None | |
| return data[key] | |
| if __name__ == '__main__': | |
| print get_vimeo_thumbnail('<some id>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment