diff --git a/includes/config.php b/includes/config.php index e09a0e1..1c0e5cb 100644 --- a/includes/config.php +++ b/includes/config.php @@ -22,6 +22,7 @@ if (!defined('TAG_INDEPENDENCE')) define('TAG_INDEPENDENCE', 'indépendance'); if (!defined('SHORTS_MAX_DURATION')) define('SHORTS_MAX_DURATION', 120); // 2 minutes max pour les shorts // Pagination et affichage +if (!defined('COUNT_VIDEO_SEARCH')) define('COUNT_VIDEO_SEARCH', 20); if (!defined('VIDEOS_PER_PAGE')) define('VIDEOS_PER_PAGE', 12); if (!defined('FEATURED_VIDEOS_COUNT')) define('FEATURED_VIDEOS_COUNT', 6); if (!defined('RECENT_VIDEOS_COUNT')) define('RECENT_VIDEOS_COUNT', 6); @@ -557,4 +558,47 @@ function formatFileSize($bytes) { return round($bytes, 2) . ' ' . $units[$pow]; } + +/** + * Recherche des vidéos selon un critère + * + * @param string $query Terme de recherche + * @param int $count Nombre de vidéos à récupérer + * @param int $start Index de départ pour la pagination + * @return array Liste des vidéos correspondant à la recherche + */ +function searchVideos($query, $count = COUNT_VIDEO_SEARCH, $start = 0) { + if (empty($query)) { + return []; + } + + // Vérifier si la recherche concerne un tag (commence par #) + $isTagSearch = false; + if (substr($query, 0, 1) === '#') { + $isTagSearch = true; + $tag = substr($query, 1); // Enlever le # du début + + // Récupérer les vidéos avec ce tag via l'API + $data = callPeerTubeApi('videos', [ + 'tagsOneOf' => $tag, + 'count' => $count, + 'start' => $start, + 'isLocal' => true, // Uniquement les vidéos locales + 'sort' => '-publishedAt' // Les plus récentes d'abord + ]); + + return formatVideosData($data['data'] ?? []); + } + + // Recherche normale (pas un tag) + $data = callPeerTubeApi('search/videos', [ + 'search' => $query, + 'count' => $count, + 'start' => $start, + 'isLocal' => true, // Uniquement les vidéos locales + 'sort' => '-publishedAt' // Les plus récentes d'abord + ]); + + return formatVideosData($data['data'] ?? []); +} ?> \ No newline at end of file