diff --git a/youtube/youtube.js b/youtube/youtube.js index e9d0b50..a6539ec 100644 --- a/youtube/youtube.js +++ b/youtube/youtube.js @@ -1,6 +1,32 @@ async function searchResults(keyword) { const results = []; try { + const youtubeRegex = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?([a-zA-Z0-9_-]{11})/; + const youtubeMatch = keyword.match(youtubeRegex); + + if (youtubeMatch) { + const videoId = youtubeMatch[1]; + try { + const response = await fetchv2("https://invidious.nikkosphere.com/api/v1/videos/" + videoId); + const data = await response.json(); + + results.push({ + title: data.title || "YouTube Video", + image: "https://proxy.piped.private.coffee" + (data.videoThumbnails && data.videoThumbnails.length > 0 ? data.videoThumbnails[0].url : ""), + href: videoId + }); + + return JSON.stringify(results); + } catch (err) { + console.error("Error fetching YouTube video:", err); + return JSON.stringify([{ + title: "Error", + image: "Error", + href: "Error" + }]); + } + } + const response = await fetchv2("https://api.piped.private.coffee/search?q=" + encodeURIComponent(keyword) + "&filter=all"); const data = await response.json();