Merge pull request 'feat(youtube): hata ayıklama ve loglama yeteneklerini iyileştir' (#2) from develope into main
Reviewed-on: #2
This commit is contained in:
@@ -707,7 +707,8 @@ function startYoutubeDownload(url) {
|
|||||||
selectedIndex: 0,
|
selectedIndex: 0,
|
||||||
thumbnail: null,
|
thumbnail: null,
|
||||||
process: null,
|
process: null,
|
||||||
error: null
|
error: null,
|
||||||
|
debug: { binary: null, args: null, logs: [] }
|
||||||
};
|
};
|
||||||
|
|
||||||
youtubeJobs.set(job.id, job);
|
youtubeJobs.set(job.id, job);
|
||||||
@@ -717,6 +718,20 @@ function startYoutubeDownload(url) {
|
|||||||
return job;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function appendYoutubeLog(job, line) {
|
||||||
|
if (!job?.debug) return;
|
||||||
|
const lines = Array.isArray(job.debug.logs) ? job.debug.logs : [];
|
||||||
|
const split = String(line || "").split(/\r?\n/);
|
||||||
|
for (const l of split) {
|
||||||
|
if (!l.trim()) continue;
|
||||||
|
lines.push(l.trim());
|
||||||
|
}
|
||||||
|
while (lines.length > 80) {
|
||||||
|
lines.shift();
|
||||||
|
}
|
||||||
|
job.debug.logs = lines;
|
||||||
|
}
|
||||||
|
|
||||||
function launchYoutubeJob(job) {
|
function launchYoutubeJob(job) {
|
||||||
const binary = getYtDlpBinary();
|
const binary = getYtDlpBinary();
|
||||||
const args = [
|
const args = [
|
||||||
@@ -728,6 +743,7 @@ function launchYoutubeJob(job) {
|
|||||||
"--write-info-json",
|
"--write-info-json",
|
||||||
job.url
|
job.url
|
||||||
];
|
];
|
||||||
|
job.debug = { binary, args, logs: [] };
|
||||||
const child = spawn(binary, args, {
|
const child = spawn(binary, args, {
|
||||||
cwd: job.savePath,
|
cwd: job.savePath,
|
||||||
env: process.env
|
env: process.env
|
||||||
@@ -736,6 +752,7 @@ function launchYoutubeJob(job) {
|
|||||||
|
|
||||||
const handleChunk = (chunk) => {
|
const handleChunk = (chunk) => {
|
||||||
const text = chunk.toString();
|
const text = chunk.toString();
|
||||||
|
appendYoutubeLog(job, text);
|
||||||
for (const raw of text.split(/\r?\n/)) {
|
for (const raw of text.split(/\r?\n/)) {
|
||||||
const line = raw.trim();
|
const line = raw.trim();
|
||||||
if (!line) continue;
|
if (!line) continue;
|
||||||
@@ -750,7 +767,14 @@ function launchYoutubeJob(job) {
|
|||||||
child.on("error", (err) => {
|
child.on("error", (err) => {
|
||||||
job.state = "error";
|
job.state = "error";
|
||||||
job.downloadSpeed = 0;
|
job.downloadSpeed = 0;
|
||||||
|
appendYoutubeLog(job, `spawn error: ${err?.message || err}`);
|
||||||
job.error = err?.message || "yt-dlp çalıştırılamadı";
|
job.error = err?.message || "yt-dlp çalıştırılamadı";
|
||||||
|
console.error("❌ yt-dlp spawn error:", {
|
||||||
|
jobId: job.id,
|
||||||
|
message: err?.message || err,
|
||||||
|
binary,
|
||||||
|
args
|
||||||
|
});
|
||||||
broadcastSnapshot();
|
broadcastSnapshot();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -829,7 +853,18 @@ async function finalizeYoutubeJob(job, exitCode) {
|
|||||||
job.downloadSpeed = 0;
|
job.downloadSpeed = 0;
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
job.state = "error";
|
job.state = "error";
|
||||||
|
const tail = job.debug?.logs ? job.debug.logs.slice(-8) : [];
|
||||||
job.error = `yt-dlp ${exitCode} kodu ile sonlandı`;
|
job.error = `yt-dlp ${exitCode} kodu ile sonlandı`;
|
||||||
|
if (tail.length) {
|
||||||
|
job.error += ` | ${tail.join(" | ")}`;
|
||||||
|
}
|
||||||
|
console.warn("❌ yt-dlp çıkış kodu hata:", {
|
||||||
|
jobId: job.id,
|
||||||
|
exitCode,
|
||||||
|
binary: job.debug?.binary,
|
||||||
|
args: job.debug?.args,
|
||||||
|
lastLines: tail
|
||||||
|
});
|
||||||
broadcastSnapshot();
|
broadcastSnapshot();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -845,6 +880,11 @@ async function finalizeYoutubeJob(job, exitCode) {
|
|||||||
if (!videoFile) {
|
if (!videoFile) {
|
||||||
job.state = "error";
|
job.state = "error";
|
||||||
job.error = "Video dosyası bulunamadı";
|
job.error = "Video dosyası bulunamadı";
|
||||||
|
console.warn("❌ yt-dlp çıktı video bulunamadı:", {
|
||||||
|
jobId: job.id,
|
||||||
|
savePath: job.savePath,
|
||||||
|
lastLines: job.debug?.logs?.slice(-8) || []
|
||||||
|
});
|
||||||
broadcastSnapshot();
|
broadcastSnapshot();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user