Update youtube/youtube.js

This commit is contained in:
aka paul 2025-11-03 18:30:31 +00:00
parent 9b1c80f7e6
commit b72a96a007

View file

@ -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();