Get the youtube video thumbnail url template filter

 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

  1. Auto Generate/Save Thumbnails using Template Filter (scale max_x, max_y, or both) by ThisbeTom 4 years, 5 months ago
  2. [UPDATE]Filter to resize a ImageField on demand by rafacdb 4 years, 9 months ago
  3. YouTube Template Filter by jgeewax 4 years, 10 months ago
  4. youtubize template tag by TheJester 6 years ago
  5. iPernity thumbnail helper by sedden 4 years, 6 months ago

Comments

maccesch (on May 31, 2011):

thanks for the snippet. you should also tag it django :)

#

(Forgotten your password?)