Compare commits

...

4 Commits

Author SHA1 Message Date
xRangerDE
6a32387add release: 4.4.0 performance optimizations, collision detection, notifications
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 09:28:42 +01:00
xRangerDE
3537d28eb2 test: add filename collision detection unit tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 09:28:06 +01:00
xRangerDE
a4ca410641 feat: filename collision detection, queue JSON validation, download-complete notification
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 09:27:19 +01:00
xRangerDE
76ecbc652d perf: parallel init with Promise.all, targeted DOM updates for download progress
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 09:26:19 +01:00
6 changed files with 89 additions and 18 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "twitch-vod-manager",
"version": "4.3.4",
"version": "4.4.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "twitch-vod-manager",
"version": "4.3.4",
"version": "4.4.0",
"license": "MIT",
"dependencies": {
"axios": "^1.6.0",

View File

@ -1,6 +1,6 @@
{
"name": "twitch-vod-manager",
"version": "4.3.4",
"version": "4.4.0",
"description": "Twitch VOD Manager - Download Twitch VODs easily",
"main": "dist/main.js",
"author": "xRangerDE",

View File

@ -105,6 +105,21 @@ function run() {
const iIndex = args.indexOf('-i');
assert(ssIndex < iIndex, `FFmpeg args: -ss (${ssIndex}) must be before -i (${iIndex})`);
// ---- Test 9: ensureUniqueFilename pattern ----
function ensureUnique(base, ext, existingFiles) {
let candidate = base + ext;
if (!existingFiles.includes(candidate)) return candidate;
let counter = 1;
while (existingFiles.includes(candidate)) {
candidate = `${base}_${counter}${ext}`;
counter++;
}
return candidate;
}
assert(ensureUnique('video', '.mp4', []) === 'video.mp4', 'Unique: no conflict');
assert(ensureUnique('video', '.mp4', ['video.mp4']) === 'video_1.mp4', 'Unique: one conflict');
assert(ensureUnique('video', '.mp4', ['video.mp4', 'video_1.mp4']) === 'video_2.mp4', 'Unique: two conflicts');
// ---- Results ----
if (failures.length > 0) {
console.error(`FAIL: ${failures.length} test(s) failed:`);

View File

@ -1,4 +1,4 @@
import { app, BrowserWindow, ipcMain, dialog, shell, nativeTheme } from 'electron';
import { app, BrowserWindow, ipcMain, dialog, shell, nativeTheme, Notification } from 'electron';
import * as path from 'path';
import * as fs from 'fs';
import { spawn, ChildProcess, execSync, exec, spawnSync } from 'child_process';
@ -340,10 +340,17 @@ function loadQueue(): QueueItem[] {
try {
if (fs.existsSync(QUEUE_FILE)) {
const data = fs.readFileSync(QUEUE_FILE, 'utf-8');
return JSON.parse(data);
const parsed = JSON.parse(data);
if (!Array.isArray(parsed)) return [];
return parsed.filter((item: any) =>
item && typeof item.id === 'string' &&
typeof item.url === 'string' &&
typeof item.status === 'string'
);
}
} catch (e) {
console.error('Error loading queue:', e);
console.error('queue-load-error', { error: String(e) });
}
return [];
}
@ -1168,6 +1175,20 @@ function formatDurationDashed(seconds: number): string {
return `${h.toString().padStart(2, '0')}-${m.toString().padStart(2, '0')}-${s.toString().padStart(2, '0')}`;
}
function ensureUniqueFilename(filePath: string): string {
if (!fs.existsSync(filePath)) return filePath;
const dir = path.dirname(filePath);
const ext = path.extname(filePath);
const base = path.basename(filePath, ext);
let counter = 1;
let candidate = filePath;
while (fs.existsSync(candidate)) {
candidate = path.join(dir, `${base}_${counter}${ext}`);
counter++;
}
return candidate;
}
function sanitizeFilenamePart(input: string, fallback = 'unnamed'): string {
const cleaned = (input || '')
.replace(/[<>:"|?*\x00-\x1f]/g, '_')
@ -2565,7 +2586,7 @@ async function splitMergedFile(
const startSec = i * partDurationSec;
const thisDuration = Math.min(partDurationSec, totalDurationSec - startSec);
const outputFile = path.join(outputFolder, filenameGenerator(i + 1));
const outputFile = ensureUniqueFilename(path.join(outputFolder, filenameGenerator(i + 1)));
onProgress(i + 1, numParts);
@ -2890,7 +2911,7 @@ async function downloadVOD(
const remainingDuration = clip.durationSec - (i * partDuration);
const thisDuration = Math.min(partDuration, remainingDuration);
const partFilename = makeClipFilename(partNum, startOffset, thisDuration);
const partFilename = ensureUniqueFilename(makeClipFilename(partNum, startOffset, thisDuration));
const result = await downloadVODPart(
item.url,
@ -2913,7 +2934,7 @@ async function downloadVOD(
};
} else {
// Single clip file
const filename = makeClipFilename(clip.startPart, clip.startSec, clip.durationSec);
const filename = ensureUniqueFilename(makeClipFilename(clip.startPart, clip.startSec, clip.durationSec));
return await downloadVODPart(
item.url,
filename,
@ -2930,13 +2951,13 @@ async function downloadVOD(
// Check download mode
if (config.download_mode === 'full' || totalDuration <= config.part_minutes * 60) {
// Full download
const filename = makeTemplateFilename(
const filename = ensureUniqueFilename(makeTemplateFilename(
config.filename_template_vod,
DEFAULT_FILENAME_TEMPLATE_VOD,
1,
0,
totalDuration
);
));
return await downloadVODPart(item.url, filename, null, null, onProgress, item.id, 1, 1);
} else {
// Part-based download
@ -2951,13 +2972,13 @@ async function downloadVOD(
const endSec = Math.min((i + 1) * partDuration, totalDuration);
const duration = endSec - startSec;
const partFilename = makeTemplateFilename(
const partFilename = ensureUniqueFilename(makeTemplateFilename(
config.filename_template_parts,
DEFAULT_FILENAME_TEMPLATE_PARTS,
i + 1,
startSec,
duration
);
));
const result = await downloadVODPart(
item.url,
@ -3041,7 +3062,7 @@ async function processDownloadMergeGroup(
saveQueue(downloadQueue);
const vodItem = mg.items[i];
const tmpFilename = path.join(folder, `merge_tmp_${i}_${Date.now()}.mp4`);
const tmpFilename = ensureUniqueFilename(path.join(folder, `merge_tmp_${i}_${Date.now()}.mp4`));
// Calculate progress weighting per VOD
const vodDuration = parseDuration(vodItem.duration_str);
@ -3364,6 +3385,18 @@ async function processQueue(): Promise<void> {
saveQueue(downloadQueue);
emitQueueUpdated();
mainWindow?.webContents.send('download-finished');
try {
if (Notification.isSupported()) {
const completed = downloadQueue.filter(i => i.status === 'completed').length;
const failed = downloadQueue.filter(i => i.status === 'error').length;
new Notification({
title: 'Twitch VOD Manager',
body: failed > 0
? `${completed} Downloads fertig, ${failed} fehlgeschlagen`
: `${completed} Downloads abgeschlossen`
}).show();
}
} catch { }
appendDebugLog('queue-finished', { items: downloadQueue.length });
}

View File

@ -179,6 +179,25 @@ async function createMergeGroupFromSelection(): Promise<void> {
updateMergeGroupButton();
}
function updateQueueItemProgress(progress: DownloadProgress): void {
const items = byId('queueList').children;
const idx = queue.findIndex(i => i.id === progress.id);
if (idx < 0 || idx >= items.length) return;
const el = items[idx];
const bar = el.querySelector('.queue-progress-bar') as HTMLElement;
const text = el.querySelector('.queue-progress-text') as HTMLElement;
const meta = el.querySelector('.queue-meta') as HTMLElement;
if (bar) {
const pct = progress.progress > 0 ? Math.min(100, progress.progress) : 0;
bar.style.width = `${pct}%`;
bar.className = `queue-progress-bar${progress.progress <= 0 ? ' indeterminate' : ''}`;
}
if (text) text.textContent = getQueueProgressText(queue[idx]);
if (meta) meta.textContent = getQueueMetaText(queue[idx]);
}
function renderQueue(): void {
if (!Array.isArray(queue)) {
queue = [];

View File

@ -5,14 +5,18 @@ const QUEUE_SYNC_HIDDEN_MS = 9000;
const QUEUE_SYNC_RECENT_ACTIVITY_WINDOW_MS = 15000;
async function init(): Promise<void> {
config = await window.api.getConfig();
const [loadedConfig, initialQueue, isDown, version] = await Promise.all([
window.api.getConfig(),
window.api.getQueue(),
window.api.isDownloading(),
window.api.getVersion()
]);
config = loadedConfig;
const language = setLanguage((config.language as string) || 'en');
config.language = language;
const initialQueue = await window.api.getQueue();
queue = Array.isArray(initialQueue) ? initialQueue : [];
downloading = await window.api.isDownloading();
downloading = isDown;
markQueueActivity();
const version = await window.api.getVersion();
byId('versionText').textContent = `v${version}`;
byId('versionInfo').textContent = `Version: v${version}`;
@ -66,7 +70,7 @@ async function init(): Promise<void> {
item.downloadedBytes = progress.downloadedBytes;
item.totalBytes = progress.totalBytes;
item.progressStatus = progress.status;
renderQueue();
updateQueueItemProgress(progress);
markQueueActivity();
});