Website / templates /Index.html
48leewsypc's picture
Rename Index.html to templates/Index.html
5c13601 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Downloader</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
input[type="url"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
width: 100%;
}
button:hover {
background-color: #45a049;
}
#status {
margin-top: 20px;
padding: 10px;
border-radius: 5px;
text-align: center;
}
.error {
background-color: #ffebee;
color: #c62828;
}
.success {
background-color: #e8f5e9;
color: #2e7d32;
}
</style>
</head>
<body>
<div class="container">
<h1>Video Downloader</h1>
<form id="downloadForm">
<div class="form-group">
<input type="url" id="url" placeholder="Enter YouTube, Instagram, or TikTok URL" required>
</div>
<button type="submit">Download</button>
</form>
<div id="status"></div>
</div>
<script>
document.getElementById('downloadForm').addEventListener('submit', async (e) => {
e.preventDefault();
const status = document.getElementById('status');
const url = document.getElementById('url').value;
status.className = '';
status.textContent = 'Downloading...';
try {
const response = await fetch('/download', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `url=${encodeURIComponent(url)}`
});
if (response.ok) {
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = 'video.mp4';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(downloadUrl);
document.body.removeChild(a);
status.className = 'success';
status.textContent = 'Download completed successfully!';
} else {
const error = await response.json();
throw new Error(error.error || 'Download failed');
}
} catch (error) {
status.className = 'error';
status.textContent = `Error: ${error.message}`;
}
});
</script>
</body>
</html>