-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
140 lines (122 loc) · 3.83 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<title>YouTube Thumbnail Downloader</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
box-sizing: border-box;
}
h1 {
color: #333;
margin-top: 0;
}
input[type="text"] {
padding: 10px;
width: 100%;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
}
select {
padding: 10px;
width: 100%;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 3px;
}
#thumbnailContainer {
margin-top: 20px;
}
#thumbnailContainer img {
max-width: 100%;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>YouTube Thumbnail Downloader</h1>
<input type="text" id="videoUrl" placeholder="Enter YouTube video URL">
<select id="resolutionSelect">
<option value="maxresdefault">Max Resolution</option>
<option value="sddefault">Standard Definition</option>
<option value="hqdefault">High Quality</option>
<option value="mqdefault">Medium Quality</option>
</select>
<button id="getThumbnailBtn">Get Thumbnail</button>
<button id="downloadBtn" disabled>Start Download</button>
<div id="thumbnailContainer"></div>
</div>
<script>
var videoUrlInput = document.getElementById("videoUrl");
var getThumbnailBtn = document.getElementById("getThumbnailBtn");
var downloadBtn = document.getElementById("downloadBtn");
getThumbnailBtn.addEventListener("click", function() {
var videoUrl = videoUrlInput.value;
var resolution = document.getElementById("resolutionSelect").value;
// Remove whitespaces and check if the URL is valid
videoUrl = videoUrl.trim();
if (videoUrl === "") {
alert("Please enter a valid YouTube video URL.");
return;
}
// Get video ID from URL
var videoId = extractVideoId(videoUrl);
if (videoId === null) {
alert("Please enter a valid YouTube video URL.");
return;
}
// Construct thumbnail URL based on resolution
var thumbnailUrl = "https://img.youtube.com/vi/" + videoId + "/" + resolution + ".jpg";
// Display thumbnail
var thumbnailImg = document.createElement("img");
thumbnailImg.src = thumbnailUrl;
var thumbnailContainer = document.getElementById("thumbnailContainer");
thumbnailContainer.innerHTML = "";
thumbnailContainer.appendChild(thumbnailImg);
// Enable download button
downloadBtn.disabled = false;
});
downloadBtn.addEventListener("click", function() {
var thumbnailImg = document.querySelector("#thumbnailContainer img");
if (!thumbnailImg) {
alert("Please get the thumbnail first.");
return;
}
var thumbnailUrl = thumbnailImg.src;
window.open(thumbnailUrl, "_blank");
});
function extractVideoId(url) {
var videoId = null;
var pattern = /(?:https?:\/\/(?:www\.)?)?youtu(?:be\.com\/(?:watch\?v=|embed\/|v\/)|\.be\/)([\w\-]+)(?:[\?&]t=([\dhms]+))?/i;
var match = url.match(pattern);
if (match && match[1].length === 11) {
videoId = match[1];
}
return videoId;
}
</script>
</body>
</html>