<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f3f3f3;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
}
div {
margin-top: 20px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
#thumbnail {
text-align: center;
margin-top: 30px;
}
#thumbnail img {
max-width: 100%;
height: auto;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Thumbnail Extractor</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>YouTube Thumbnail Extractor</h1>
<div>
<label for="video-url">Enter YouTube Video URL:</label>
<input type="text" id="video-url" placeholder="https://www.youtube.com/watch?v=YOUR_VIDEO_ID">
<button onclick="extractThumbnail()">Extract Thumbnail</button>
</div>
<div id="thumbnail"></div>
<script src="script.js"></script>
<script>
function extractThumbnail() {
var videoUrl = document.getElementById('video-url').value;
var videoId = getVideoId(videoUrl);
var thumbnailUrl = "https://img.youtube.com/vi/" + videoId + "/maxresdefault.jpg";
if (videoId) {
document.getElementById('thumbnail').innerHTML = '<img src="' + thumbnailUrl + '" alt="YouTube Video Thumbnail">';
} else {
document.getElementById('thumbnail').innerHTML = 'Invalid YouTube Video URL';
}
}
function getVideoId(url) {
var videoId = '';
if (url.indexOf('?v=') > -1) {
videoId = url.split('?v=')[1];
} else if (url.indexOf('&v=') > -1) {
videoId = url.split('&v=')[1];
} else if (url.indexOf('youtu.be/') > -1) {
videoId = url.split('youtu.be/')[1];
}
return videoId.indexOf('&') > -1 ? videoId.split('&')[0] : videoId;
}
</script>
</body>
</html>
0 Comments