Search

I'm trying to determine the best way to add thumbnail images to a list of Vimeo videos. The list is generated from a data source where you enter the Vimeo video ID for each item.

To get the thumbnails for specific videos on Vimeo you need to query their API: http://vimeo.com/api/v2/video/{$vimeo-id}.xml

Which will return the following XML:

videos> <video> <id>20368827</id> <title>Warbringer - "Combat Shock"</title> <description> Exit, Prague, Czech Republic (5.09.10)<br /> <br /> Bangover Tour </description> <url>http://vimeo.com/20368827</url> <upload_date>2011-02-25 08:28:48</upload_date> <thumbnail_small>http://b.vimeocdn.com/ts/130/144/130144886_100.jpg</thumbnail_small> <thumbnail_medium>http://b.vimeocdn.com/ts/130/144/130144886_200.jpg</thumbnail_medium> <thumbnail_large>http://b.vimeocdn.com/ts/130/144/130144886_640.jpg</thumbnail_large> <user_name>serdzoid</user_name> <user_url>http://vimeo.com/serdzoid</user_url> <user_portrait_small>http://b.vimeocdn.com/ps/182/466/1824661_30.jpg</user_portrait_small> <user_portrait_medium>http://b.vimeocdn.com/ps/182/466/1824661_75.jpg</user_portrait_medium> <user_portrait_large>http://b.vimeocdn.com/ps/182/466/1824661_100.jpg</user_portrait_large> <user_portrait_huge>http://b.vimeocdn.com/ps/182/466/1824661_300.jpg</user_portrait_huge> <stats_number_of_likes>0</stats_number_of_likes> <stats_number_of_plays>1</stats_number_of_plays> <stats_number_of_comments>0</stats_number_of_comments> <duration>256</duration> <width>640</width> <height>360</height> <tags/> </video> </videos>

This could then be transformed to to produce the images. However I can't find a straight forward way to do this for each Vimeo item on a page due to the declarative nature of XSLT (and I'm not XSLT ninja). What would be the best approach here?

Well you can load the returned XML in a variable via document() function and use it as usual

<xsl:variable name="path" select="concat(`http://vimeo.com/api/v2/video/`, $vimeo-id, `.xml`) />
<xsl:variable name="video-info" select="document($path)" />

<xsl:value-of select="$video-info/videos/video/thumbnail_medium" />

<img src="$video-info/videos/video/thumbnail_medium" />

Untested, but it should work.

@vladG, that's a great solution, exactly what I was hoping could be done. Thanks!

You're welcome.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details