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