File size: 7,086 Bytes
ed98528 |
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube to MP3</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
margin-bottom: 30px;
}
input[type="url"] {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 15px;
box-sizing: border-box;
}
button {
background: #ff0000;
color: white;
padding: 12px 30px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
width: 100%;
}
button:hover {
background: #cc0000;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
#status {
margin-top: 20px;
padding: 15px;
border-radius: 5px;
display: none;
}
.analyzing { background: #fff3cd; }
.downloading { background: #d1ecf1; }
.completed { background: #d4edda; }
.error { background: #f8d7da; }
#progress {
margin-top: 10px;
font-weight: bold;
}
.task-list {
margin-top: 30px;
}
.task-item {
background: #f9f9f9;
padding: 15px;
border-radius: 5px;
margin-bottom: 10px;
cursor: pointer;
}
.task-item:hover {
background: #eee;
}
.task-url {
font-size: 14px;
color: #666;
margin-bottom: 5px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.task-status {
font-weight: bold;
margin-bottom: 5px;
}
.task-completed { color: #28a745; }
.task-downloading { color: #17a2b8; }
.task-error { color: #dc3545; }
</style>
</head>
<body>
<div class="container">
<h1>🎵 YouTube to MP3</h1>
<p>Entrez une URL YouTube (vidéo ou playlist)</p>
<input type="url" id="urlInput" placeholder="https://www.youtube.com/watch?v=..." />
<button onclick="startDownload()">Télécharger</button>
<div id="status"></div>
<div id="progress"></div>
<div class="task-list">
<h3>Tâches récentes</h3>
<div id="tasksList"></div>
</div>
</div>
<script>
let currentTaskId = null;
let tasks = JSON.parse(localStorage.getItem('tasks') || '[]');
function saveTasks() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function renderTasks() {
const list = document.getElementById('tasksList');
list.innerHTML = '';
tasks.slice().reverse().forEach(task => {
const div = document.createElement('div');
div.className = 'task-item';
div.onclick = () => checkStatus(task.id);
let statusClass = '';
let statusText = '';
if (task.status === 'completed') {
statusClass = 'task-completed';
statusText = '✓ Terminé';
} else if (task.status === 'downloading' || task.status === 'analyzing') {
statusClass = 'task-downloading';
statusText = `⏳ ${task.progress}/${task.total}`;
} else if (task.status === 'error') {
statusClass = 'task-error';
statusText = '✗ Erreur';
}
div.innerHTML = `
<div class="task-status ${statusClass}">${statusText}</div>
<div class="task-url">${task.url}</div>
`;
list.appendChild(div);
});
}
async function startDownload() {
const url = document.getElementById('urlInput').value;
if (!url) {
alert('Veuillez entrer une URL');
return;
}
const response = await fetch('/download', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url })
});
const data = await response.json();
if (data.error) {
alert(data.error);
return;
}
currentTaskId = data.task_id;
tasks.push({ id: currentTaskId, url: url, status: 'analyzing', progress: 0, total: 0 });
saveTasks();
renderTasks();
checkStatus(currentTaskId);
}
async function checkStatus(taskId) {
currentTaskId = taskId;
const response = await fetch(`/status/${taskId}`);
const data = await response.json();
const statusDiv = document.getElementById('status');
const progressDiv = document.getElementById('progress');
statusDiv.style.display = 'block';
statusDiv.className = data.status;
if (data.status === 'analyzing') {
statusDiv.textContent = '📊 Analyse de la playlist...';
} else if (data.status === 'downloading') {
statusDiv.textContent = '📥 Téléchargement en cours...';
progressDiv.textContent = `${data.progress}/${data.total} vidéos`;
} else if (data.status === 'completed') {
statusDiv.textContent = '✅ Téléchargement terminé!';
progressDiv.innerHTML = `<a href="/download/${taskId}" style="color: #007bff;">📦 Télécharger le ZIP</a>`;
} else if (data.status === 'error') {
statusDiv.textContent = '❌ Erreur: ' + data.error;
progressDiv.textContent = '';
}
const taskIndex = tasks.findIndex(t => t.id === taskId);
if (taskIndex !== -1) {
tasks[taskIndex] = { ...tasks[taskIndex], status: data.status, progress: data.progress, total: data.total };
saveTasks();
renderTasks();
}
if (data.status === 'downloading' || data.status === 'analyzing') {
setTimeout(() => checkStatus(taskId), 2000);
}
}
renderTasks();
</script>
</body>
</html> |