Spaces:
Running
Running
File size: 22,872 Bytes
e711652 |
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Lounge Viewer</title>
<!-- Importation de la police Inter -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap" rel="stylesheet">
<!-- Importation de FontAwesome pour les icônes -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* --- VARIABLES CSS & THEME --- */
:root {
--bg-body: #0f0f0f;
--bg-sidebar: #1e1e1e;
--bg-card: #2a2a2a;
--bg-input: #333333;
--text-primary: #ffffff;
--text-secondary: #aaaaaa;
--accent-color: #ff0000; /* YouTube Red */
--accent-hover: #cc0000;
--border-color: #3f3f3f;
--shadow: 0 4px 15px rgba(0,0,0,0.5);
--transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
--header-height: 70px;
}
/* --- RESET & BASE --- */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
outline: none;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg-body);
color: var(--text-primary);
height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden; /* Empêche le scroll global, on scroll dans les zones */
}
a { text-decoration: none; color: inherit; }
ul { list-style: none; }
button { cursor: pointer; border: none; font-family: inherit; }
/* --- HEADER --- */
header {
height: var(--header-height);
background-color: rgba(30, 30, 30, 0.95);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 2rem;
z-index: 100;
}
.logo {
font-size: 1.5rem;
font-weight: 700;
display: flex;
align-items: center;
gap: 10px;
}
.logo i { color: var(--accent-color); font-size: 1.8rem; }
.header-controls {
display: flex;
align-items: center;
gap: 1.5rem;
}
.anycoder-link {
font-size: 0.85rem;
color: var(--text-secondary);
transition: var(--transition);
background: rgba(255, 255, 255, 0.05);
padding: 5px 10px;
border-radius: 4px;
}
.anycoder-link:hover {
color: var(--text-primary);
background: rgba(255, 255, 255, 0.1);
}
/* --- MAIN LAYOUT --- */
main {
flex: 1;
display: grid;
grid-template-columns: 1fr 350px; /* Player area | Sidebar */
height: calc(100vh - var(--header-height));
overflow: hidden;
}
/* --- PLAYER SECTION --- */
.player-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 2rem;
background-color: #000;
position: relative;
}
.video-wrapper {
width: 100%;
max-width: 1200px;
aspect-ratio: 16 / 9;
background: #111;
border-radius: 12px;
overflow: hidden;
box-shadow: var(--shadow);
position: relative;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
.video-info {
width: 100%;
max-width: 1200px;
margin-top: 1.5rem;
}
.video-title {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 0.5rem;
line-height: 1.3;
}
.video-meta {
color: var(--text-secondary);
font-size: 0.9rem;
display: flex;
gap: 1rem;
}
/* --- SIDEBAR / PLAYLIST --- */
.sidebar {
background-color: var(--bg-sidebar);
border-left: 1px solid var(--border-color);
display: flex;
flex-direction: column;
height: 100%;
}
.sidebar-header {
padding: 1.5rem;
border-bottom: 1px solid var(--border-color);
}
.sidebar-title {
font-size: 1.2rem;
font-weight: 600;
margin-bottom: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
/* Formulaire d'ajout */
.add-video-form {
display: flex;
flex-direction: column;
gap: 10px;
}
.input-group {
position: relative;
}
.input-group i {
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
color: var(--text-secondary);
}
input[type="text"], input[type="url"] {
width: 100%;
background-color: var(--bg-input);
border: 1px solid transparent;
color: var(--text-primary);
padding: 10px 10px 10px 35px;
border-radius: 6px;
font-size: 0.9rem;
transition: var(--transition);
}
input:focus {
border-color: var(--accent-color);
background-color: #3a3a3a;
}
.btn-add {
background-color: var(--accent-color);
color: white;
padding: 10px;
border-radius: 6px;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: var(--transition);
}
.btn-add:hover {
background-color: var(--accent-hover);
transform: translateY(-1px);
}
/* Liste des vidéos */
.playlist {
flex: 1;
overflow-y: auto;
padding: 1rem;
}
/* Scrollbar custom */
.playlist::-webkit-scrollbar { width: 6px; }
.playlist::-webkit-scrollbar-track { background: var(--bg-sidebar); }
.playlist::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
.playlist::-webkit-scrollbar-thumb:hover { background: #555; }
.playlist-item {
display: flex;
gap: 10px;
padding: 10px;
border-radius: 8px;
cursor: pointer;
transition: var(--transition);
margin-bottom: 8px;
border: 1px solid transparent;
}
.playlist-item:hover {
background-color: var(--bg-card);
}
.playlist-item.active {
background-color: rgba(255, 0, 0, 0.1);
border-color: rgba(255, 0, 0, 0.3);
}
.playlist-thumb {
width: 100px;
height: 56px; /* 16:9 approx */
background-color: #000;
border-radius: 4px;
overflow: hidden;
flex-shrink: 0;
position: relative;
}
.playlist-thumb img {
width: 100%;
height: 100%;
object-fit: cover;
}
.playlist-info {
display: flex;
flex-direction: column;
justify-content: center;
overflow: hidden;
}
.playlist-title {
font-size: 0.9rem;
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 4px;
}
.playlist-actions {
margin-top: auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.btn-delete {
color: var(--text-secondary);
font-size: 0.8rem;
padding: 4px;
transition: color 0.2s;
}
.btn-delete:hover { color: var(--accent-color); }
.empty-state {
text-align: center;
color: var(--text-secondary);
margin-top: 2rem;
font-size: 0.9rem;
}
/* --- CINEMA MODE --- */
body.cinema-mode header,
body.cinema-mode .sidebar {
display: none;
}
body.cinema-mode main {
grid-template-columns: 1fr;
height: 100vh;
}
body.cinema-mode .player-container {
height: 100vh;
padding: 0;
}
body.cinema-mode .video-wrapper {
max-width: 100%;
border-radius: 0;
height: 100%;
}
.btn-cinema {
background: transparent;
color: var(--text-primary);
font-size: 1.2rem;
padding: 8px;
border-radius: 50%;
transition: var(--transition);
}
.btn-cinema:hover {
background-color: rgba(255,255,255,0.1);
}
/* --- TOAST NOTIFICATIONS --- */
#toast-container {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
display: flex;
flex-direction: column;
gap: 10px;
z-index: 1000;
}
.toast {
background-color: #333;
color: #fff;
padding: 12px 24px;
border-radius: 50px;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
font-size: 0.9rem;
display: flex;
align-items: center;
gap: 10px;
animation: slideUp 0.3s ease-out forwards;
min-width: 250px;
justify-content: center;
}
.toast.success { border-left: 4px solid #4caf50; }
.toast.error { border-left: 4px solid #f44336; }
@keyframes slideUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
/* --- RESPONSIVE --- */
@media (max-width: 900px) {
main {
grid-template-columns: 1fr;
overflow-y: auto;
height: auto;
}
.player-container {
padding: 1rem;
min-height: 50vh;
}
.sidebar {
border-left: none;
border-top: 1px solid var(--border-color);
height: auto;
}
.playlist {
max-height: 500px;
}
}
</style>
</head>
<body>
<!-- Header -->
<header>
<div class="logo">
<i class="fa-brands fa-youtube"></i>
<span>YT Lounge</span>
</div>
<div class="header-controls">
<button class="btn-cinema" id="cinema-toggle" title="Mode Cinéma">
<i class="fa-solid fa-expand"></i>
</button>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">
Built with anycoder
</a>
</div>
</header>
<!-- Main Content -->
<main>
<!-- Player Section -->
<section class="player-container">
<div class="video-wrapper">
<!-- Iframe YouTube par défaut -->
<iframe id="yt-player"
src="https://www.youtube.com/embed/jfKfPfyJRdk?enablejsapi=1"
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
</div>
<div class="video-info">
<h1 class="video-title" id="current-title">Lofi Hip Hop Radio - Beats to Relax/Study to</h1>
<div class="video-meta">
<span><i class="fa-regular fa-clock"></i> Lecture en cours</span>
<span><i class="fa-solid fa-tv"></i> YouTube Embed</span>
</div>
</div>
</section>
<!-- Sidebar / Playlist -->
<aside class="sidebar">
<div class="sidebar-header">
<div class="sidebar-title">
<span>Mes Vidéos</span>
<span style="font-size: 0.8rem; font-weight: 400; color: var(--text-secondary);" id="playlist-count">0</span>
</div>
<form class="add-video-form" id="add-form">
<div class="input-group">
<i class="fa-solid fa-link"></i>
<input type="url" id="video-url" placeholder="Lien YouTube (ex: youtube.com/watch?v=...)" required>
</div>
<!-- Optionnel : Titre personnalisé, sinon on utilisera l'ID généré -->
<button type="submit" class="btn-add">
<i class="fa-solid fa-plus"></i> Ajouter
</button>
</form>
</div>
<ul class="playlist" id="playlist">
<!-- Les éléments seront injectés ici par JS -->
</ul>
</aside>
</main>
<!-- Toast Container -->
<div id="toast-container"></div>
<script>
/**
* APPLICATION YOUTUBE LOUNGE
* Logique : Vanilla JS
* Stockage : LocalStorage
*/
// --- État de l'application ---
let playlist = [];
const STORAGE_KEY = 'yt_lounge_playlist_v1';
// Éléments DOM
const playlistEl = document.getElementById('playlist');
const playerEl = document.getElementById('yt-player');
const currentTitleEl = document.getElementById('current-title');
const addForm = document.getElementById('add-form');
const urlInput = document.getElementById('video-url');
const playlistCountEl = document.getElementById('playlist-count');
const cinemaToggle = document.getElementById('cinema-toggle');
// --- Initialisation ---
document.addEventListener('DOMContentLoaded', () => {
loadPlaylist();
// Si la playlist est vide au premier lancement, ajouter une vidéo par défaut
if (playlist.length === 0) {
addVideoToState('https://www.youtube.com/watch?v=jfKfPfyJRdk', 'Lofi Hip Hop Radio - Beats to Relax/Study to');
} else {
// Charger la première vidéo
loadVideo(playlist[0].id);
}
renderPlaylist();
});
// --- Fonctions Principales ---
// 1. Charger la playlist depuis le LocalStorage
function loadPlaylist() {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored) {
try {
playlist = JSON.parse(stored);
} catch (e) {
console.error("Erreur de lecture du storage", e);
playlist = [];
}
}
}
// 2. Sauvegarder dans le LocalStorage
function savePlaylist() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(playlist));
updateCount();
}
// 3. Extraire l'ID YouTube depuis une URL
function extractYouTubeID(url) {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
const match = url.match(regExp);
return (match && match[2].length === 11) ? match[2] : null;
}
// 4. Ajouter une vidéo
function addVideoToState(url, customTitle = null) {
const videoId = extractYouTubeID(url);
if (!videoId) {
showToast("Lien YouTube invalide", "error");
return false;
}
// Vérifier doublon
const exists = playlist.find(v => v.id === videoId);
if (exists) {
showToast("Cette vidéo est déjà dans la liste", "error");
return false;
}
const title = customTitle || `Vidéo YouTube (${videoId})`;
const newVideo = {
id: videoId,
title: title,
thumbnail: `https://img.youtube.com/vi/${videoId}/mqdefault.jpg`,
addedAt: Date.now()
};
playlist.unshift(newVideo); // Ajouter au début
savePlaylist();
renderPlaylist();
showToast("Vidéo ajoutée avec succès", "success");
return true;
}
// 5. Charger une vidéo dans le lecteur
function loadVideo(id) {
// Mise à jour de l'iframe
playerEl.src = `https://www.youtube.com/embed/${id}?autoplay=1&rel=0`;
// Mise à jour de l'UI active
document.querySelectorAll('.playlist-item').forEach(item => {
item.classList.remove('active');
if(item.dataset.id === id) {
item.classList.add('active');
}
});
// Mise à jour du titre
const vidObj = playlist.find(v => v.id === id);
if (vidObj) {
currentTitleEl.textContent = vidObj.title;
}
}
// 6. Supprimer une vidéo
function deleteVideo(id, event) {
event.stopPropagation(); // Empêcher le clic de jouer la vidéo
if(confirm("Voulez-vous vraiment supprimer cette vidéo de la liste ?")) {
playlist = playlist.filter(v => v.id !== id);
savePlaylist();
renderPlaylist();
showToast("Vidéo supprimée", "success");
// Si on supprime la vidéo en cours, on peut remettre la première ou arrêter
// Ici on laisse la iframe telle quelle pour ne pas couper brutalement
}
}
// 7. Rendu de la liste
function renderPlaylist() {
playlistEl.innerHTML = '';
if (playlist.length === 0) {
playlistEl.innerHTML = `
<div class="empty-state">
<i class="fa-solid fa-film" style="font-size: 2rem; margin-bottom: 10px; display:block;"></i>
Votre liste est vide.<br>Ajoutez un lien YouTube ci-dessus.
</div>
`;
updateCount();
return;
}
playlist.forEach(video => {
const li = document.createElement('li');
li.className = 'playlist-item';
li.dataset.id = video.id;
li.onclick = () => loadVideo(video.id);
li.innerHTML = `
<div class="playlist-thumb">
<img src="${video.thumbnail}" alt="Thumbnail" loading="lazy">
</div>
<div class="playlist-info">
<div class="playlist-title" title="${video.title}">${video.title}</div>
<div class="playlist-actions">
<span style="font-size: 0.7rem; color: #666;">ID: ${video.id}</span>
<button class="btn-delete" onclick="deleteVideo('${video.id}', event)" title="Supprimer">
<i class="fa-solid fa-trash"></i>
</button>
</div>
</div>
`;
playlistEl.appendChild(li);
});
updateCount();
}
function updateCount() {
playlistCountEl.textContent = playlist.length;
}
// --- Gestion des événements ---
addForm.addEventListener('submit', (e) => {
e.preventDefault();
const url = urlInput.value.trim();
if (!url) return;
const success = addVideoToState(url);
if (success) {
urlInput.value = '';
}
});
// Mode Cinéma
cinemaToggle.addEventListener('click', () => {
document.body.classList.toggle('cinema-mode');
const isCinema = document.body.classList.contains('cinema-mode');
const icon = cinemaToggle.querySelector('i');
if (isCinema) {
icon.classList.remove('fa-expand');
icon.classList.add('fa-compress');
showToast("Mode Cinéma activé. Appuyez sur Esc pour quitter.", "success");
} else {
icon.classList.remove('fa-compress');
icon.classList.add('fa-expand');
}
});
// Quitter le mode cinéma avec Echap
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && document.body.classList.contains('cinema-mode')) {
document.body.classList.remove('cinema-mode');
cinemaToggle.querySelector('i').classList.remove('fa-compress');
cinemaToggle.querySelector('i').classList.add('fa-expand');
}
});
// --- Système de Toast (Notifications) ---
function showToast(message, type = 'success') {
const container = document.getElementById('toast-container');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
const icon = type === 'success' ? '<i class="fa-solid fa-check-circle"></i>' : '<i class="fa-solid fa-exclamation-circle"></i>';
toast.innerHTML = `${icon} <span>${message}</span>`;
container.appendChild(toast);
// Auto remove
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transform = 'translateY(20px)';
toast.addEventListener('transitionend', () => {
toast.remove();
});
}, 3000);
}
</script>
</body>
</html> |