YouTube Thumbnail Downloader
YouTube Thumbnail Downloader
/* styles.css */
body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #ff7e5f, #feb47b);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
color: #333;
}
form {
margin-bottom: 20px;
}
input[type="text"] {
width: 80%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 10px;
font-size: 16px;
}
button {
padding: 10px 20px;
border: none;
background-color: #ff7e5f;
color: white;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #feb47b;
}
.thumbnails {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 10px;
}
.thumbnail img {
width: 100%;
height: auto;
border-radius: 5px;
transition: transform 0.3s ease;
}
.thumbnail img:hover {
transform: scale(1.05);
}
.thumbnail {
flex: 1 1 calc(33.333% - 10px);
max-width: calc(33.333% - 10px);
margin-bottom: 10px;
}
// script.js
document.getElementById('thumbnailForm').addEventListener('submit', function(e) {
e.preventDefault();
const videoUrl = document.getElementById('videoUrl').value;
const videoId = getYouTubeVideoId(videoUrl);
if (videoId) {
displayThumbnails(videoId);
} else {
alert('Invalid YouTube URL. Please enter a valid URL.');
}
});
function getYouTubeVideoId(url) {
const regex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
const match = url.match(regex);
return match ? match[1] : null;
}
function displayThumbnails(videoId) {
const thumbnailBaseUrl = `https://img.youtube.com/vi/${videoId}/`;
const thumbnailSizes = ['0', '1', '2', '3', 'mqdefault', 'hqdefault', 'sddefault', 'maxresdefault'];
const thumbnailsDiv = document.getElementById('thumbnails');
thumbnailsDiv.innerHTML = '';
thumbnailSizes.forEach(size => {
const imgUrl = `${thumbnailBaseUrl}${size}.jpg`;
const imgElement = document.createElement('img');
imgElement.src = imgUrl;
imgElement.alt = `Thumbnail ${size}`;
const thumbnailDiv = document.createElement('div');
thumbnailDiv.className = 'thumbnail';
thumbnailDiv.appendChild(imgElement);
thumbnailsDiv.appendChild(thumbnailDiv);
});
}