You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[const API_KEY = "YT TOKEN HERE";
async function getLiveStreamDetails(channelOrVideoId) {
let apiUrl;
if (channelOrVideoId.length === 24) {
apiUrl = https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${channelOrVideoId}&type=video&eventType=live&key=${API_KEY};
} else {
apiUrl = https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${channelOrVideoId}&key=${API_KEY};
}
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(Error en la solicitud a la API de YouTube: ${response.statusText});
}
const data = await response.json();
if (channelOrVideoId.length === 24) {
// Validación para ID de canal
if (data.items.length === 0) {
throw new Error("No hay transmisiones en vivo disponibles para este canal.");
}
return data.items[0].id.videoId;
} else {
// Validación para ID de video
if (data.items.length === 0) {
throw new Error("El ID del video proporcionado no es válido o no está en vivo.");
}
return channelOrVideoId;
}
}
async function getManifestUrl(videoId, type) {
if (type === "dash") {
return https://www.youtube.com/watch?v=${videoId};
} else if (type === "hls") {
return https://www.youtube.com/watch?v=${videoId};
} else {
throw new Error("Tipo de manifiesto no válido. Usa 'dash' o 'hls'.");
}
}
async function handleRequest(request) {
const url = new URL(request.url);
const pathParts = url.pathname.split("/");
const resourceType = pathParts[3]; // master.mpd o master.m3u8
const channelOrVideoId = pathParts[2];
Yes, configured a key for the Youtube V3 API and inserted it into your script. Problem is that your code has many formatting/syntax errors, probably you had a problem copy pasting this into this thread. Could you message me the js file that you are currently using (without your API key of course) so I can be sure that your idea works?
have somne fixes, and need to enable yt token
[const API_KEY = "YT TOKEN HERE";
async function getLiveStreamDetails(channelOrVideoId) {
let apiUrl;
if (channelOrVideoId.length === 24) {
apiUrl =
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${channelOrVideoId}&type=video&eventType=live&key=${API_KEY}
;} else {
apiUrl =
https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${channelOrVideoId}&key=${API_KEY}
;}
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error(
Error en la solicitud a la API de YouTube: ${response.statusText}
);}
const data = await response.json();
if (channelOrVideoId.length === 24) {
// Validación para ID de canal
if (data.items.length === 0) {
throw new Error("No hay transmisiones en vivo disponibles para este canal.");
}
return data.items[0].id.videoId;
} else {
// Validación para ID de video
if (data.items.length === 0) {
throw new Error("El ID del video proporcionado no es válido o no está en vivo.");
}
return channelOrVideoId;
}
}
async function getManifestUrl(videoId, type) {
if (type === "dash") {
return
https://www.youtube.com/watch?v=${videoId}
;} else if (type === "hls") {
return
https://www.youtube.com/watch?v=${videoId}
;} else {
throw new Error("Tipo de manifiesto no válido. Usa 'dash' o 'hls'.");
}
}
async function handleRequest(request) {
const url = new URL(request.url);
const pathParts = url.pathname.split("/");
const resourceType = pathParts[3]; // master.mpd o master.m3u8
const channelOrVideoId = pathParts[2];
try {
const videoId = await getLiveStreamDetails(channelOrVideoId);
} catch (error) {
return new Response(error.message, { status: 500 });
}
}
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack || "Error interno del servidor", { status: 500 })
)
);
}); ]
The text was updated successfully, but these errors were encountered: