forked from 50n50/sources
Update youtube/youtube.js
This commit is contained in:
@@ -1,6 +1,32 @@
|
|||||||
async function searchResults(keyword) {
|
async function searchResults(keyword) {
|
||||||
const results = [];
|
const results = [];
|
||||||
try {
|
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 response = await fetchv2("https://api.piped.private.coffee/search?q=" + encodeURIComponent(keyword) + "&filter=all");
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user