Login

Get the youtube video thumbnail url template filter

Author:
fitoria
Posted:
October 16, 2010
Language:
Python
Version:
Not specified
Tags:
template-filter thumbnail youtube
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

  1. YouTube Template Filter by jgeewax 7 years ago
  2. youtubize template tag by TheJester 8 years, 2 months ago
  3. ultralize by catellar 3 years, 10 months ago
  4. "Youtube watch link to embed" custom tag. by I159 3 years, 9 months ago
  5. convert youtube url for iframe, js api by ivanff 2 years, 3 months ago

Comments

maccesch (on May 31, 2011):

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

#

Please login first before commenting.