- Author:
- fitoria
- Posted:
- October 16, 2010
- Language:
- Python
- Version:
- Not specified
- Score:
- 2 (after 2 ratings)
It gets the thumbnail picture url from a youtube video url.
Example <img src="{{vide.url|youthumbnail:'s'}}">
It supports 2 sizes small(s) and large (l)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
thanks for the snippet. you should also tag it django :)
#
Please login first before commenting.