Get Youtube thumbnail
I am developing a Discord bot, but I have a problem, how can I use YouTube video thumbnails?
7 Replies
my bot finds and plays the song from YouTube, but I want to use the video thumbnail as well
Be aware that playing songs off of YouTube through eg. a bot is against YouTube's terms of service.
In any case, YouTube has an official API you can use to fetch video metadata like thumbnails, titles, descriptions, etc.
Google for Developers
YouTube Data API | Google for Developers
Add YouTube features to your application, including the ability to upload videos, create and manage playlists, and more.
There are C# nuget packages for this
For thumbnails you just take the video ID and slap it in either of these links
https://img.youtube.com/vi/VIDEO_ID/maxresdefault.jpg
https://img.youtube.com/vi/VIDEO_ID/hqdefault.jpg
https://img.youtube.com/vi/VIDEO_ID/mqdefault.jpg
Bear in mind, sometimes the highest quality is not available so a placeholder is put that looks like this:
Here's a regex to get the video id from a link
An example usage of this would be
Video: https://www.youtube.com/watch?v=rK3-tO7K6i8
Thumbnail link: https://img.youtube.com/vi/rK3-tO7K6i8/maxresdefault.jpg
Nick Chapsas
YouTube
The New Data Protection Features of .NET 8 (GDPR)
Use code CLEAN20 and get 20% off the brand new "Deep Dive in Clean Architecture" course on Dometrain: https://dometrain.com/course/deep-dive-clean-architecture-in-dotnet/?coupon_code=CLEAN20
Get the source code: https://mailchi.mp/dometrain/rk3-to7k6i8
Become a Patreon and get special perks: https://www.patreon.com/nickchapsas
Hello everybody...