Fix: Enhance error handling for playlist fetch failures by retrying with single video

This commit is contained in:
MasterAcnolo
2026-04-12 17:34:17 +02:00
parent 5dc61b4a15
commit 912f4042e5

View File

@@ -22,7 +22,32 @@ async function infoController(req, res){
}
try {
const data = await fetchInfo(url);
let data;
let fetchError = null;
try {
data = await fetchInfo(url);
} catch (err) {
fetchError = err;
// If it's a playlist URL and fetch failed, try fetching just the single video
if ((url.includes("&list") || url.includes("?list"))) {
logger.info(`Playlist fetch failed: ${err.message}. Retrying with single video...`);
// Remove the &list parameter
const singleVideoUrl = url.split("&list")[0].split("?list")[0];
try {
data = await fetchInfo(singleVideoUrl);
logger.info(`Single video fetch succeeded after playlist failure`);
} catch (retryErr) {
logger.error(`Single video fetch also failed: ${retryErr.message}`);
throw err; // Throw the original error
}
} else {
throw err;
}
}
if (data._type === "playlist") {