This code creates a simple web page with an input field for the YouTube video URL and a button to fetch the thumbnail. When the button is clicked, the getThumbnail()
function is called, which extracts the YouTube video ID from the URL and constructs the thumbnail URL using the extractThumbnailUrl()
and getVideoId()
functions.
The thumbnail URL is then assigned to the src
attribute of the <img>
tag with the ID "thumbnail-image". If an invalid YouTube video URL is entered, an alert is shown.
Please note that this is a basic implementation and may not work for all possible variations of YouTube video URLs. It's always recommended to use a dedicated library or API for parsing YouTube URLs and retrieving thumbnails in a real-world scenario.