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:
2025-12-14 12:12:09 +00:00

View File

@@ -707,7 +707,8 @@ function startYoutubeDownload(url) {
selectedIndex: 0,
thumbnail: null,
process: null,
error: null
error: null,
debug: { binary: null, args: null, logs: [] }
};
youtubeJobs.set(job.id, job);
@@ -717,6 +718,20 @@ function startYoutubeDownload(url) {
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) {
const binary = getYtDlpBinary();
const args = [
@@ -728,6 +743,7 @@ function launchYoutubeJob(job) {
"--write-info-json",
job.url
];
job.debug = { binary, args, logs: [] };
const child = spawn(binary, args, {
cwd: job.savePath,
env: process.env
@@ -736,6 +752,7 @@ function launchYoutubeJob(job) {
const handleChunk = (chunk) => {
const text = chunk.toString();
appendYoutubeLog(job, text);
for (const raw of text.split(/\r?\n/)) {
const line = raw.trim();
if (!line) continue;
@@ -750,7 +767,14 @@ function launchYoutubeJob(job) {
child.on("error", (err) => {
job.state = "error";
job.downloadSpeed = 0;
appendYoutubeLog(job, `spawn error: ${err?.message || err}`);
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();
});
}
@@ -829,7 +853,18 @@ async function finalizeYoutubeJob(job, exitCode) {
job.downloadSpeed = 0;
if (exitCode !== 0) {
job.state = "error";
const tail = job.debug?.logs ? job.debug.logs.slice(-8) : [];
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();
return;
}
@@ -845,6 +880,11 @@ async function finalizeYoutubeJob(job, exitCode) {
if (!videoFile) {
job.state = "error";
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();
return;
}