Recently I’ve been asked how easy it will be to get the initial screenshot of a youtube video attached in an email template with as less pain as possible.

A bit of googling told me that you can get all public information of a video using the following endpoing

https://gdata.youtube.com/feeds/api/videos/videoid?v=2

By using one of my favourite songs…

http://www.youtube.com/watch?v=OguPPZ_7u60

The request becomes…

https://gdata.youtube.com/feeds/api/videos/OguPPZ_7u60?v=2

Just to test a bit whats going on I’ve tested the url with

curl -I https://gdata.youtube.com/feeds/api/videos/OguPPZ_7u60?v=2

Lets check the contents of the url

curl https://gdata.youtube.com/feeds/api/videos/OguPPZ_7u60?v=2

It’s an xml file with a lof of information…lets save it in a file

curl https://gdata.youtube.com/feeds/api/videos/OguPPZ_7u60?v=2 > my_favourite_music_video_data.xml

Opening the file with vim the xml is all within a single line…I cannot read it like this, I need to

:%s/></>\r</g

and voi la!!!….

youtube api

I have the url that gives me a reasonable quality thumbnail of a video..

https://i1.ytimg.com/vi/OguPPZ_7u60/hqdefault.jpg

all that I need now is an easy way for the user to give the video code and just replace it in an img tag source that will point to the url above!! :)

Cheers