This post will help you if you want to get the preview image for a YouTube video. You may want to you this if you want to trigger the video to launch in a pop up window, or you want to link to the video.

I'm not sure how far back it goes, but it works for PSY's Gangnam Style which is from July 2012 and Justin Beiber's Baby which is from February 2010.

You need the id of the video which is in the url after v=
https://www.youtube.com/watch?v=cIboJm2WzKY

When you have the video id, you can use it in this url to get the image.
URL

https://i.ytimg.com/vi/{0}/maxresdefault.jpg
@{
string youTubeId = "cIboJm2WzKY";
const string YOUTUBE_PREVIEW_IMAGE_URL = "https://i.ytimg.com/vi/{0}/maxresdefault.jpg";
}

<img src="@String.Format(YOUTUBE_PREVIEW_IMAGE_URL, youTubeId)" />

//The output will be

<img src="https://i.ytimg.com/vi/cIboJm2WzKY/maxresdefault.jpg">

I trust this has been pretty straight forward for you to follow. If you have any questions, feel free to write them in the comments. Don't forget to share this post with your friends and colleagues.

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Proudly sponsored by

Moriyama

  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.
AppVeyor

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.
stkrs

  • Custom stickers for startups, artists and brands.
  • Bespoke easy-apply, removable, custom brand stickers printed in the UK.
elmah.io

  • elmah.io is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.