Skip to content

Commit c62a451

Browse files
committed
Add resumable thumbnail extraction Also improves initial import by skipping any already existing thumbnails.
1 parent 3d46999 commit c62a451

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

main-support.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,28 @@ export function superDangerousDelete(imageLocation: string, numberOfImage: numbe
302302

303303
// GENERATE INDEXES FOR ARRAY
304304

305+
export function hasAllThumbs(fileHash: string, screenshotFolder: string) : boolean {
306+
// Check in reverse order for efficiency
307+
return fs.existsSync(screenshotFolder + '/' + fileHash + '-first.jpg')
308+
&& fs.existsSync(screenshotFolder + '/' + fileHash + '.mp4')
309+
&& fs.existsSync(screenshotFolder + '/' + fileHash + '.jpg');
310+
}
311+
312+
/**
313+
* Generate indexes for any files missing thumbnails
314+
*/
315+
export function missingThumbsIndex(fullArray: ImageElement[], screenshotFolder: string): number[] {
316+
const indexes: number[] = [];
317+
const total: number = fullArray.length;
318+
for (let i = 0; i < total; i++) {
319+
if (!hasAllThumbs(fullArray[i][3], screenshotFolder)) {
320+
indexes.push(i);
321+
}
322+
}
323+
324+
return indexes;
325+
}
326+
305327
/**
306328
* Generate indexes for each element in finalArray, e.g.
307329
* [0, 1, 2, 3, ..., n] where n = finalArray.length

main.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ ffmpeg.setFfmpegPath(ffmpegPath);
198198
import {
199199
alphabetizeFinalArray,
200200
countFoldersInFinalArray,
201+
missingThumbsIndex,
201202
everyIndex,
202203
extractAllMetadata,
203204
finalArrayWithoutDeleted,
@@ -253,6 +254,19 @@ function openThisDamnFile(pathToVhaFile: string) {
253254
console.log(globals.selectedSourceFolder + ' - videos location');
254255
console.log(globals.selectedOutputFolder + ' - output location');
255256

257+
// resume extracting any missing thumbnails
258+
const screenshotOutputFolder: string = path.join(globals.selectedOutputFolder, 'vha-' + globals.hubName);
259+
260+
const indexesToScan: number[] = missingThumbsIndex(lastSavedFinalObject.images, screenshotOutputFolder);
261+
262+
extractAllScreenshots(
263+
lastSavedFinalObject.images,
264+
globals.selectedSourceFolder,
265+
screenshotOutputFolder,
266+
globals.screenShotSize,
267+
indexesToScan
268+
);
269+
256270
globals.angularApp.sender.send(
257271
'finalObjectReturning',
258272
JSON.parse(data),
@@ -625,7 +639,7 @@ function sendFinalResultHome(
625639

626640
const screenshotOutputFolder: string = path.join(globals.selectedOutputFolder, 'vha-' + globals.hubName);
627641

628-
const indexesToScan: number[] = everyIndex(myFinalArray);
642+
const indexesToScan: number[] = missingThumbsIndex(myFinalArray, screenshotOutputFolder);
629643

630644
extractAllScreenshots(
631645
myFinalArray,

0 commit comments

Comments
 (0)