Created
October 16, 2010 17:16
-
-
Save fitoria/630042 to your computer and use it in GitHub Desktop.
Get youtube thumbnail django template filter
This file contains 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
from urlparse import parse_qs | |
from django import template | |
from django.template.defaultfilters import stringfilter | |
register = template.Library() | |
@stringfilter | |
def youthumbnail(value, args): | |
'''returns youtube thumb url | |
args s, l (small, large)''' | |
qs = value.split('?') | |
video_id = parse_qs(qs[1])['v'][0] | |
if args == 's': | |
return "http://img.youtube.com/vi/%s/2.jpg" % video_id | |
elif args == 'l': | |
return "http://img.youtube.com/vi/%s/0.jpg" % video_id | |
else: | |
return None | |
register.filter('youthumbnail', youthumbnail) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment