Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You do this by observing that YouTube video thumbnails have a distinct URL pattern, which you can generate by parse out the video id. Vimeo thumbnails can be obtained similarly, but parsing out the video id and then using the <a href="http://vimeo.com/api/docs/simple-api#video" rel="nofollow noreferrer">simple API</a> to obtain the link to the thumbnail. </p> <p>I wrote some code to do this for <a href="https://meta.stackexchange.com/questions/71234/add-chat-like-youtube-support-to-stack-exchange">this Meta question</a>; it's not particularly clean but it should work: </p> <pre><code>function processURL(url, success){ var id; if (url.indexOf('youtube.com') &gt; -1) { id = url.split('/')[1].split('v=')[1].split('&amp;')[0]; return processYouTube(id); } else if (url.indexOf('youtu.be') &gt; -1) { id = url.split('/')[1]; return processYouTube(id); } else if (url.indexOf('vimeo.com') &gt; -1) { if (url.match(/^vimeo.com\/[0-9]+/)) { id = url.split('/')[1]; } else if (url.match(/^vimeo.com\/channels\/[\d\w]+#[0-9]+/)) { id = url.split('#')[1]; } else if (url.match(/vimeo.com\/groups\/[\d\w]+\/videos\/[0-9]+/)) { id = url.split('/')[4]; } else { throw new Error('Unsupported Vimeo URL'); } $.ajax({ url: 'http://vimeo.com/api/v2/video/' + id + '.json', dataType: 'jsonp', success: function(data) { sucess(data[0].thumbnail_large); } }); } else { throw new Error('Unrecognised URL'); } function processYouTube(id) { if (!id) { throw new Error('Unsupported YouTube URL'); } sucess('http://i2.ytimg.com/vi/' + id + '/hqdefault.jpg'); } } </code></pre> <p>The function uses a callback because Vimeo API calls are asynchronous. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload