Add comments and switch in logger module for console.log

This commit is contained in:
mmcwilliams 2019-08-04 17:54:38 -04:00
parent bd79025305
commit 30c36baa9c
7 changed files with 104 additions and 67 deletions

View File

@ -5,12 +5,21 @@ const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec");
/** @class FFMPEG **/
class FFMPEG {
/**
* @constructor
* Creates an ffmpeg class
*
* @param {object} sys System object to be used to get temp directory
**/
constructor(sys) {
this.id = 'ffmpeg';
this.system = sys;
this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
this.init();
}
/**
* Async method to call async functions from constructor
**/
async init() {
const Log = require('log');
this.log = await Log({ label: this.id });
@ -71,25 +80,25 @@ class FFMPEG {
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try {
console.log(cmd);
this.log.info(cmd);
output = await exec_1.exec(cmd);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (output && output.stdout)
console.log(`"${output.stdout}"`);
this.log.info(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
this.log.info(cmd2);
output2 = await exec_1.exec(cmd2);
}
catch (err) {
console.error(err);
this.log.error(err);
}
}
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
this.log.info(`"${output2.stdout}"`);
return tmpoutput;
}
/**
@ -113,7 +122,7 @@ class FFMPEG {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
@ -139,16 +148,16 @@ class FFMPEG {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
this.log.info(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
this.log.error(err);
}
return true;
}
@ -163,7 +172,7 @@ class FFMPEG {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (files) {
files.forEach(async (file, index) => {
@ -171,7 +180,7 @@ class FFMPEG {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
this.log.error(err);
}
});
}
@ -186,22 +195,22 @@ class FFMPEG {
fileExists = await fs_extra_1.exists(this.TMPDIR);
}
catch (err) {
console.error('Error checking for tmp dir', err);
this.log.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await fs_extra_1.mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
this.log.info(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
this.log.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
}
catch (err) {
console.error(err);
this.log.error(err);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -5,12 +5,21 @@ const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec");
/** @class FFMPEG **/
class FFMPEG {
/**
* @constructor
* Creates an ffmpeg class
*
* @param {object} sys System object to be used to get temp directory
**/
constructor(sys) {
this.id = 'ffmpeg';
this.system = sys;
this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
this.init();
}
/**
* Async method to call async functions from constructor
**/
async init() {
const Log = require('log');
this.log = await Log({ label: this.id });
@ -71,25 +80,25 @@ class FFMPEG {
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try {
console.log(cmd);
this.log.info(cmd);
output = await exec_1.exec(cmd);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (output && output.stdout)
console.log(`"${output.stdout}"`);
this.log.info(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
this.log.info(cmd2);
output2 = await exec_1.exec(cmd2);
}
catch (err) {
console.error(err);
this.log.error(err);
}
}
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
this.log.info(`"${output2.stdout}"`);
return tmpoutput;
}
/**
@ -113,7 +122,7 @@ class FFMPEG {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
@ -139,16 +148,16 @@ class FFMPEG {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
this.log.info(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
this.log.error(err);
}
return true;
}
@ -163,7 +172,7 @@ class FFMPEG {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (files) {
files.forEach(async (file, index) => {
@ -171,7 +180,7 @@ class FFMPEG {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
this.log.error(err);
}
});
}
@ -186,22 +195,22 @@ class FFMPEG {
fileExists = await fs_extra_1.exists(this.TMPDIR);
}
catch (err) {
console.error('Error checking for tmp dir', err);
this.log.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await fs_extra_1.mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
this.log.info(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
this.log.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
}
catch (err) {
console.error(err);
this.log.error(err);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -5,12 +5,21 @@ const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec");
/** @class FFMPEG **/
class FFMPEG {
/**
* @constructor
* Creates an ffmpeg class
*
* @param {object} sys System object to be used to get temp directory
**/
constructor(sys) {
this.id = 'ffmpeg';
this.system = sys;
this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
this.init();
}
/**
* Async method to call async functions from constructor
**/
async init() {
const Log = require('log');
this.log = await Log({ label: this.id });
@ -71,25 +80,25 @@ class FFMPEG {
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try {
console.log(cmd);
this.log.info(cmd);
output = await exec_1.exec(cmd);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (output && output.stdout)
console.log(`"${output.stdout}"`);
this.log.info(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
this.log.info(cmd2);
output2 = await exec_1.exec(cmd2);
}
catch (err) {
console.error(err);
this.log.error(err);
}
}
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
this.log.info(`"${output2.stdout}"`);
return tmpoutput;
}
/**
@ -113,7 +122,7 @@ class FFMPEG {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
@ -139,16 +148,16 @@ class FFMPEG {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
this.log.info(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
this.log.error(err);
}
return true;
}
@ -163,7 +172,7 @@ class FFMPEG {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
this.log.error(err);
}
if (files) {
files.forEach(async (file, index) => {
@ -171,7 +180,7 @@ class FFMPEG {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
this.log.error(err);
}
});
}
@ -186,22 +195,22 @@ class FFMPEG {
fileExists = await fs_extra_1.exists(this.TMPDIR);
}
catch (err) {
console.error('Error checking for tmp dir', err);
this.log.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await fs_extra_1.mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
this.log.info(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
this.log.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
}
catch (err) {
console.error(err);
this.log.error(err);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -16,11 +16,21 @@ class FFMPEG {
private log : any;
private id : string = 'ffmpeg';
private TMPDIR : string;
/**
* @constructor
* Creates an ffmpeg class
*
* @param {object} sys System object to be used to get temp directory
**/
constructor (sys : any) {
this.system = sys;
this.TMPDIR = join(this.system.tmp, 'mcopy_digital');
this.init()
}
/**
* Async method to call async functions from constructor
**/
async init () {
const Log = require('log');
this.log = await Log({ label : this.id });
@ -90,23 +100,23 @@ class FFMPEG {
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try {
console.log(cmd);
this.log.info(cmd);
output = await exec(cmd);
} catch (err) {
console.error(err);
this.log.error(err);
}
if (output && output.stdout) console.log(`"${output.stdout}"`);
if (output && output.stdout) this.log.info(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
this.log.info(cmd2);
output2 = await exec(cmd2);
} catch (err) {
console.error(err);
this.log.error(err);
}
}
if (output2 && output2.stdout) console.log(`"${output2.stdout}"`);
if (output2 && output2.stdout) this.log.info(`"${output2.stdout}"`);
return tmpoutput
}
@ -132,7 +142,7 @@ class FFMPEG {
try {
await mkdir(tmppath);
} catch (err) {
console.error(err);
this.log.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
@ -162,16 +172,16 @@ class FFMPEG {
try {
fileExists = await exists(tmppath);
} catch (err) {
console.error(err);
this.log.error(err);
}
if (!exists) return false;
try {
await unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
this.log.info(`Cleared frame ${tmppath}`);
} catch (err) {
console.error(err);
this.log.error(err);
}
return true;
@ -187,14 +197,14 @@ class FFMPEG {
try {
files = await readdir(tmppath);
} catch (err) {
console.error(err);
this.log.error(err);
}
if (files) {
files.forEach(async (file : string, index : any) => {
try {
await unlink(join(tmppath, file));
} catch (err) {
console.error(err);
this.log.error(err);
}
});
}
@ -209,21 +219,21 @@ class FFMPEG {
try {
fileExists = await exists(this.TMPDIR);
} catch (err) {
console.error('Error checking for tmp dir', err);
this.log.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
this.log.info(`Created tmpdir ${this.TMPDIR}`);
} catch (err) {
console.error('Error creating tmp dir', err);
this.log.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
} catch (err) {
console.error(err);
this.log.error(err);
}
}
}