$video['uuid'], 'title' => $video['name'] ?? '', 'thumbnail' => $thumbnail, 'duration' => $video['duration'] ?? 0, 'channel' => $video['channel']['displayName'] ?? '', 'channelAvatar' => $channelAvatar, 'views' => $video['views'] ?? 0, 'date' => $video['publishedAt'] ?? '', 'aspectRatio' => $video['aspectRatio'] ?? null, 'description' => $video['description'] ?? '', 'tags' => $video['tags'] ?? [], 'isLive' => $video['isLive'] ?? false ]; } return $videos; } // Fonctions utilitaires pour formater les données d'affichage function formatDuration($seconds) { $hours = floor($seconds / 3600); $minutes = floor(($seconds % 3600) / 60); $remainingSeconds = $seconds % 60; if ($hours > 0) { return sprintf('%d:%02d:%02d', $hours, $minutes, $remainingSeconds); } else { return sprintf('%d:%02d', $minutes, $remainingSeconds); } } function formatViewCount($views) { if ($views >= 1000000) { return round($views / 1000000, 1) . 'M'; } elseif ($views >= 1000) { return round($views / 1000, 1) . 'K'; } else { return $views; } } function formatDate($dateString) { // Chaîne vide : rien à formater (new DateTime('') renverrait « maintenant ») if (!is_string($dateString) || trim($dateString) === '') { return (string) $dateString; } try { $date = new DateTime($dateString); } catch (Exception $e) { // Date malformée (données API inattendues) : afficher la chaîne brute return $dateString; } $now = new DateTime(); $interval = $now->diff($date); if ($interval->days == 0) { return 'Aujourd\'hui'; } elseif ($interval->days == 1) { return 'Hier'; } elseif ($interval->days < 7) { return 'Il y a ' . $interval->days . ' jours'; } elseif ($interval->days < 30) { $weeks = floor($interval->days / 7); return 'Il y a ' . $weeks . ' semaine' . ($weeks > 1 ? 's' : ''); } elseif ($interval->days < 365) { $months = floor($interval->days / 30); return 'Il y a ' . $months . ' mois'; } else { $years = floor($interval->days / 365); return 'Il y a ' . $years . ' an' . ($years > 1 ? 's' : ''); } } /** * Formate la taille d'un fichier en format lisible * @param int $bytes Taille en octets * @return string Taille formatée */ function formatFileSize($bytes) { $units = ['B', 'KB', 'MB', 'GB', 'TB']; $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= (1 << (10 * $pow)); return round($bytes, 2) . ' ' . $units[$pow]; }