Skip to content

Commit

Permalink
Add resumable thumbnail extraction Also improves initial import by sk…
Browse files Browse the repository at this point in the history
…ipping any already existing thumbnails.
  • Loading branch information
cal2195 committed Dec 10, 2018
1 parent 3d46999 commit 4092b3e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
24 changes: 23 additions & 1 deletion main-support.ts
Expand Up @@ -17,7 +17,7 @@ import { globals } from './main-globals';
*/
export function hashFile(fileName: string, fileSize: number): string {
// make the magic happen!
let hash = hasher('md5').update(fileName + fileSize).digest('hex');
let hash = hasher('md5').update(fileName + fileSize.toString()).digest('hex');
return hash;
}

Expand Down Expand Up @@ -302,6 +302,28 @@ export function superDangerousDelete(imageLocation: string, numberOfImage: numbe

// GENERATE INDEXES FOR ARRAY

export function hasAllThumbs(fileHash: string, screenshotFolder: string) : boolean {
// Check in reverse order for efficiency
return fs.existsSync(screenshotFolder + '/' + fileHash + '-first.jpg')
&& fs.existsSync(screenshotFolder + '/' + fileHash + '.mp4')
&& fs.existsSync(screenshotFolder + '/' + fileHash + '.jpg');
}

/**
* Generate indexes for any files missing thumbnails
*/
export function missingThumbsIndex(fullArray: ImageElement[], screenshotFolder: string): number[] {
const indexes: number[] = [];
const total: number = fullArray.length;
for (let i = 0; i < total; i++) {
if (!hasAllThumbs(fullArray[i][3], screenshotFolder)) {
indexes.push(i);
}
}

return indexes;
}

/**
* Generate indexes for each element in finalArray, e.g.
* [0, 1, 2, 3, ..., n] where n = finalArray.length
Expand Down
16 changes: 15 additions & 1 deletion main.ts
Expand Up @@ -198,6 +198,7 @@ ffmpeg.setFfmpegPath(ffmpegPath);
import {
alphabetizeFinalArray,
countFoldersInFinalArray,
missingThumbsIndex,
everyIndex,
extractAllMetadata,
finalArrayWithoutDeleted,
Expand Down Expand Up @@ -253,6 +254,19 @@ function openThisDamnFile(pathToVhaFile: string) {
console.log(globals.selectedSourceFolder + ' - videos location');
console.log(globals.selectedOutputFolder + ' - output location');

// resume extracting any missing thumbnails
const screenshotOutputFolder: string = path.join(globals.selectedOutputFolder, 'vha-' + globals.hubName);

const indexesToScan: number[] = missingThumbsIndex(lastSavedFinalObject.images, screenshotOutputFolder);

extractAllScreenshots(
lastSavedFinalObject.images,
globals.selectedSourceFolder,
screenshotOutputFolder,
globals.screenShotSize,
indexesToScan
);

globals.angularApp.sender.send(
'finalObjectReturning',
JSON.parse(data),
Expand Down Expand Up @@ -625,7 +639,7 @@ function sendFinalResultHome(

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

const indexesToScan: number[] = everyIndex(myFinalArray);
const indexesToScan: number[] = missingThumbsIndex(myFinalArray, screenshotOutputFolder);

extractAllScreenshots(
myFinalArray,
Expand Down

0 comments on commit 4092b3e

Please sign in to comment.