You can get the YouTube thumbnail if you don’t want to create and use an API key from Google with this simple trick:
YouTube uses a consistent URL pattern for their video thumbnails, which is:
https://img.youtube.com/vi/<video_id>/maxresdefault.jpg
The <video_id>
is the part after "watch?v="
in the YouTube video link.
For example, consider the video at https://www.youtube.com/watch?v=A5I55aOgX2o with the video identifier A5I55aOgX2o.

Here’s a simple Python function that will build this URL for you:
def get_thumbnail_url(video_id): return f"https://img.youtube.com/vi/{video_id}/maxresdefault.jpg" video_id = "VIDEO_ID" # Replace with your YouTube video ID thumbnail_url = get_thumbnail_url(video_id) print(thumbnail_url)
This will print out the URL of the thumbnail image. However, please note that this method might not always provide the highest-resolution thumbnail, primarily if the uploaded video doesn’t support high resolution.
Here’s the thumbnail in the above video example: https://img.youtube.com/vi/A5I55aOgX2o/maxresdefault.jpg with the video identifier A5I55aOgX2o.

If you want to download the image, you can use the urllib
and shutil
libraries:
import shutil import urllib.request def download_thumbnail(video_id): thumbnail_url = get_thumbnail_url(video_id) with urllib.request.urlopen(thumbnail_url) as response, open('thumbnail.jpg', 'wb') as out_file: shutil.copyfileobj(response, out_file) download_thumbnail(video_id)
This will save the thumbnail image as 'thumbnail.jpg'
in the current directory.

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.