mirror of
https://git.luna-app.eu/50n50/sources
synced 2025-12-21 13:16:21 +01:00
Update youtube/youtube.js
This commit is contained in:
parent
9b1c80f7e6
commit
b72a96a007
1 changed files with 26 additions and 0 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue