Complete major refactor
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
const isElectron = require('is-electron');
|
||||
|
||||
module.exports = (key) => {
|
||||
const env = {};
|
||||
|
||||
if (isElectron()) {
|
||||
env.type = 'electron';
|
||||
} else if (typeof window === 'object') {
|
||||
env.type = 'browser';
|
||||
} else if (typeof importScripts === 'function') {
|
||||
env.type = 'webworker';
|
||||
} else if (typeof process === 'object' && typeof require === 'function') {
|
||||
env.type = 'node';
|
||||
}
|
||||
|
||||
if (typeof key === 'undefined') {
|
||||
return env;
|
||||
}
|
||||
|
||||
return env[key];
|
||||
};
|
||||
@@ -1,9 +1,24 @@
|
||||
let logging = false;
|
||||
let customLogger = () => {};
|
||||
|
||||
exports.logging = logging;
|
||||
|
||||
exports.setLogging = (_logging) => {
|
||||
const setLogging = (_logging) => {
|
||||
logging = _logging;
|
||||
};
|
||||
|
||||
exports.log = (type, message) => (logging ? console.log(`[${type}] ${message}`) : null);
|
||||
const setCustomLogger = (logger) => {
|
||||
customLogger = logger;
|
||||
};
|
||||
|
||||
const log = (type, message) => {
|
||||
customLogger({ type, message });
|
||||
if (logging) {
|
||||
console.log(`[${type}] ${message}`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
logging,
|
||||
setLogging,
|
||||
setCustomLogger,
|
||||
log,
|
||||
};
|
||||
|
||||
@@ -1,51 +1,9 @@
|
||||
module.exports = (cmd) => {
|
||||
const args = [];
|
||||
let nextDelimiter = 0;
|
||||
let prevDelimiter = 0;
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
while ((nextDelimiter = cmd.indexOf(' ', prevDelimiter)) >= 0) {
|
||||
let arg = cmd.substring(prevDelimiter, nextDelimiter);
|
||||
let quoteIdx = arg.indexOf('\'');
|
||||
let dblQuoteIdx = arg.indexOf('"');
|
||||
|
||||
if (quoteIdx === 0 || dblQuoteIdx === 0) {
|
||||
/* The argument has a quote at the start i.e, 'id=0,streams=0 id=1,streams=1' */
|
||||
const delimiter = arg[0];
|
||||
const endDelimiter = cmd.indexOf(delimiter, prevDelimiter + 1);
|
||||
|
||||
if (endDelimiter < 0) {
|
||||
throw new Error(`Bad command escape sequence ${delimiter} near ${nextDelimiter}`);
|
||||
}
|
||||
|
||||
arg = cmd.substring(prevDelimiter + 1, endDelimiter);
|
||||
prevDelimiter = endDelimiter + 2;
|
||||
args.push(arg);
|
||||
} else if (quoteIdx > 0 || dblQuoteIdx > 0) {
|
||||
/* The argument has a quote in it, it must be ended correctly i,e. title='test' */
|
||||
if (quoteIdx === -1) quoteIdx = Infinity;
|
||||
if (dblQuoteIdx === -1) dblQuoteIdx = Infinity;
|
||||
const delimiter = (quoteIdx < dblQuoteIdx) ? '\'' : '"';
|
||||
const quoteOffset = Math.min(quoteIdx, dblQuoteIdx);
|
||||
const endDelimiter = cmd.indexOf(delimiter, prevDelimiter + quoteOffset + 1);
|
||||
|
||||
if (endDelimiter < 0) {
|
||||
throw new Error(`Bad command escape sequence ${delimiter} near ${nextDelimiter}`);
|
||||
}
|
||||
|
||||
arg = cmd.substring(prevDelimiter, endDelimiter + 1);
|
||||
prevDelimiter = endDelimiter + 2;
|
||||
args.push(arg);
|
||||
} else if (arg !== '') {
|
||||
args.push(arg);
|
||||
prevDelimiter = nextDelimiter + 1;
|
||||
} else {
|
||||
prevDelimiter = nextDelimiter + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (prevDelimiter !== cmd.length) {
|
||||
args.push(cmd.substring(prevDelimiter));
|
||||
}
|
||||
|
||||
return args;
|
||||
module.exports = (Core, args) => {
|
||||
const argsPtr = Core._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
|
||||
args.forEach((s, idx) => {
|
||||
const buf = Core._malloc(s.length + 1);
|
||||
Core.writeAsciiToMemory(s, buf);
|
||||
Core.setValue(argsPtr + (Uint32Array.BYTES_PER_ELEMENT * idx), buf, 'i32');
|
||||
});
|
||||
return [args.length, argsPtr];
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@ const ts2sec = (ts) => {
|
||||
return (parseFloat(h) * 60 * 60) + (parseFloat(m) * 60) + parseFloat(s);
|
||||
};
|
||||
|
||||
module.exports = ({ message }, progress) => {
|
||||
module.exports = (message, progress) => {
|
||||
if (typeof message === 'string') {
|
||||
if (message.startsWith(' Duration')) {
|
||||
const ts = message.split(', ')[0].split(': ')[1];
|
||||
@@ -19,6 +19,7 @@ module.exports = ({ message }, progress) => {
|
||||
progress({ ratio: t / duration });
|
||||
} else if (message.startsWith('video:')) {
|
||||
progress({ ratio: 1 });
|
||||
duration = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
const isBrowser = require('./getEnvironment')('type') === 'browser';
|
||||
const resolveURL = isBrowser ? require('resolve-url') : s => s; // eslint-disable-line
|
||||
|
||||
module.exports = (options) => {
|
||||
const opts = { ...options };
|
||||
['corePath'].forEach((key) => {
|
||||
if (typeof options[key] !== 'undefined') {
|
||||
opts[key] = resolveURL(opts[key]);
|
||||
}
|
||||
});
|
||||
return opts;
|
||||
};
|
||||
@@ -1,8 +0,0 @@
|
||||
module.exports = (Module, s) => {
|
||||
const ptr = Module._malloc((s.length + 1) * Uint8Array.BYTES_PER_ELEMENT);
|
||||
for (let i = 0; i < s.length; i += 1) {
|
||||
Module.setValue(ptr + i, s.charCodeAt(i), 'i8');
|
||||
}
|
||||
Module.setValue(ptr + s.length, 0, 'i8');
|
||||
return ptr;
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
const string2pointer = require('./string2pointer');
|
||||
|
||||
module.exports = (Module, strList) => {
|
||||
const listPtr = Module._malloc(strList.length * Uint32Array.BYTES_PER_ELEMENT);
|
||||
|
||||
strList.forEach((s, idx) => {
|
||||
const strPtr = string2pointer(Module, s);
|
||||
Module.setValue(listPtr + (4 * idx), strPtr, 'i32');
|
||||
});
|
||||
|
||||
return listPtr;
|
||||
};
|
||||
Reference in New Issue
Block a user