Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/main/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ ${stderrOutput}`;
const info = JSON.parse(infoData);
await fs.promises.unlink(infoJsonPath);
const realId = info.id;
const mediaFile = files.find(

// Refresh file list to catch any file operations that completed in the meantime
const currentFiles = await fs.promises.readdir(this.videoPath);

const mediaFile = currentFiles.find(
(f) =>
(f.startsWith(videoInfo.id) || f.startsWith(realId)) &&
!f.endsWith('.json') &&
Expand All @@ -351,7 +355,7 @@ ${stderrOutput}`;
if (!mediaFile) throw new Error('Media file not found after download.');
const mediaFilePath = path.join(this.videoPath, mediaFile);
let finalCoverPath = null;
const thumbFile = files.find(
const thumbFile = currentFiles.find(
(f) =>
(f.startsWith(videoInfo.id) || f.startsWith(realId)) &&
(f.endsWith('.jpg') || f.endsWith('.webp'))
Expand All @@ -366,7 +370,7 @@ ${stderrOutput}`;
? url.pathToFileURL(finalCoverPath).href
: null;
let subFileUri = null;
const subFile = files.find(
const subFile = currentFiles.find(
(f) => f.startsWith(videoInfo.id) && f.endsWith('.vtt')
);
if (subFile) {
Expand All @@ -376,7 +380,7 @@ ${stderrOutput}`;
});
subFileUri = url.pathToFileURL(destSub).href;
}
const descFile = files.find(
const descFile = currentFiles.find(
(f) => f.startsWith(videoInfo.id) && f.endsWith('.description')
);
if (descFile)
Expand Down
Binary file modified src/main/main.js
Binary file not shown.