|
|
@@ -37,22 +37,42 @@ export class HandbrakeService {
|
|
|
|
|
|
hb.stdout.on('data', (data) => {
|
|
|
const str = data.toString();
|
|
|
- // Parse progress from stdout
|
|
|
- const progressMatch = str.match(
|
|
|
- /Encoding: task \d+ of \d+, (\d+\.\d+)%/,
|
|
|
+ this.logger.debug(`HandBrake stdout: ${str}`);
|
|
|
+ console.log('[STDOUT]', str);
|
|
|
+ // Parse progress from stdout - try multiple patterns
|
|
|
+ let progressMatch = str.match(
|
|
|
+ /Encoding: task \d+ of \d+, (\d+(?:\.\d+)?)\s*%/,
|
|
|
);
|
|
|
+ if (!progressMatch) {
|
|
|
+ // Try alternative pattern
|
|
|
+ progressMatch = str.match(/(\d+(?:\.\d+)?)\s*%/);
|
|
|
+ }
|
|
|
if (progressMatch) {
|
|
|
const percent = Math.round(parseFloat(progressMatch[1]));
|
|
|
+ console.log(
|
|
|
+ `[MATCH] Found progress: ${percent}%, lastPercent: ${lastPercent}, taskId: ${taskId}`,
|
|
|
+ );
|
|
|
if (percent !== lastPercent) {
|
|
|
lastPercent = percent;
|
|
|
progressStarted = true;
|
|
|
|
|
|
+ console.log(`[UPDATE] Progress ${percent}% for task ${taskId}`);
|
|
|
+
|
|
|
// Update task progress if we have a task ID
|
|
|
if (taskId) {
|
|
|
+ console.log(
|
|
|
+ `[DB] Updating task ${taskId} progress to ${percent}%`,
|
|
|
+ );
|
|
|
this.db.updateTask(taskId, { progress: percent });
|
|
|
+ console.log(`[DB] Update complete`);
|
|
|
+ } else {
|
|
|
+ console.warn('[WARN] No taskId provided!');
|
|
|
}
|
|
|
|
|
|
// Emit progress update
|
|
|
+ console.log(
|
|
|
+ `[WS] Emitting progress event for task ${taskId}: ${percent}%`,
|
|
|
+ );
|
|
|
this.eventsGateway.emitTaskUpdate({
|
|
|
type: 'progress',
|
|
|
taskId,
|
|
|
@@ -62,6 +82,7 @@ export class HandbrakeService {
|
|
|
preset,
|
|
|
progress: percent,
|
|
|
});
|
|
|
+ console.log(`[WS] Emit complete`);
|
|
|
}
|
|
|
}
|
|
|
this.logger.log(str);
|
|
|
@@ -69,19 +90,41 @@ export class HandbrakeService {
|
|
|
|
|
|
hb.stderr.on('data', (data) => {
|
|
|
const str = data.toString();
|
|
|
- // Parse progress from stderr as fallback
|
|
|
- const progressMatch = str.match(
|
|
|
- /Encoding: task \d+ of \d+, (\d+\.\d+)%/,
|
|
|
+ this.logger.debug(`HandBrake stderr: ${str}`);
|
|
|
+ console.log('[STDERR]', str);
|
|
|
+ // Parse progress from stderr as fallback - try multiple patterns
|
|
|
+ let progressMatch = str.match(
|
|
|
+ /Encoding: task \d+ of \d+, (\d+(?:\.\d+)?)\s*%/,
|
|
|
);
|
|
|
+ if (!progressMatch) {
|
|
|
+ // Try alternative pattern
|
|
|
+ progressMatch = str.match(/(\d+(?:\.\d+)?)\s*%/);
|
|
|
+ }
|
|
|
if (progressMatch && !progressStarted) {
|
|
|
const percent = Math.round(parseFloat(progressMatch[1]));
|
|
|
+ console.log(
|
|
|
+ `[STDERR MATCH] Found progress: ${percent}%, lastPercent: ${lastPercent}, taskId: ${taskId}`,
|
|
|
+ );
|
|
|
if (percent !== lastPercent) {
|
|
|
lastPercent = percent;
|
|
|
|
|
|
+ console.log(
|
|
|
+ `[STDERR UPDATE] Progress ${percent}% for task ${taskId}`,
|
|
|
+ );
|
|
|
+
|
|
|
if (taskId) {
|
|
|
+ console.log(
|
|
|
+ `[STDERR DB] Updating task ${taskId} progress to ${percent}%`,
|
|
|
+ );
|
|
|
this.db.updateTask(taskId, { progress: percent });
|
|
|
+ console.log(`[STDERR DB] Update complete`);
|
|
|
+ } else {
|
|
|
+ console.warn('[STDERR WARN] No taskId provided!');
|
|
|
}
|
|
|
|
|
|
+ console.log(
|
|
|
+ `[STDERR WS] Emitting progress event for task ${taskId}: ${percent}%`,
|
|
|
+ );
|
|
|
this.eventsGateway.emitTaskUpdate({
|
|
|
type: 'progress',
|
|
|
taskId,
|
|
|
@@ -91,6 +134,7 @@ export class HandbrakeService {
|
|
|
preset,
|
|
|
progress: percent,
|
|
|
});
|
|
|
+ console.log(`[STDERR WS] Emit complete`);
|
|
|
}
|
|
|
}
|
|
|
this.logger.error(str);
|
|
|
@@ -157,13 +201,14 @@ export class HandbrakeService {
|
|
|
// Parse the output to extract presets
|
|
|
const lines = output.split('\n');
|
|
|
const presets: string[] = [];
|
|
|
- let inPresets = false;
|
|
|
+
|
|
|
for (const line of lines) {
|
|
|
- if (line.includes('Available presets:')) {
|
|
|
- inPresets = true;
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (inPresets && line.trim() && !line.startsWith(' ')) {
|
|
|
+ // Preset names start with exactly 4 spaces (not 8 for descriptions)
|
|
|
+ if (
|
|
|
+ line.startsWith(' ') &&
|
|
|
+ !line.startsWith(' ') &&
|
|
|
+ line.trim().length > 0
|
|
|
+ ) {
|
|
|
presets.push(line.trim());
|
|
|
}
|
|
|
}
|