|
@@ -10,6 +10,8 @@ const FileSync = require('lowdb/adapters/FileSync');
|
|
|
const chokidar = require('chokidar');
|
|
const chokidar = require('chokidar');
|
|
|
const hbjs = require('handbrake-js');
|
|
const hbjs = require('handbrake-js');
|
|
|
|
|
|
|
|
|
|
+const settings = require('./data/settings.json');
|
|
|
|
|
+
|
|
|
const args = minimist(process.argv.slice(2), {
|
|
const args = minimist(process.argv.slice(2), {
|
|
|
alias: {
|
|
alias: {
|
|
|
h: 'help',
|
|
h: 'help',
|
|
@@ -43,35 +45,13 @@ String.prototype.toTitleCase = function() {
|
|
|
});
|
|
});
|
|
|
// Certain minor words should be left lowercase unless
|
|
// Certain minor words should be left lowercase unless
|
|
|
// they are the first or last words in the string
|
|
// they are the first or last words in the string
|
|
|
- lowers = [
|
|
|
|
|
- 'A',
|
|
|
|
|
- 'An',
|
|
|
|
|
- 'The',
|
|
|
|
|
- 'And',
|
|
|
|
|
- 'But',
|
|
|
|
|
- 'Or',
|
|
|
|
|
- 'For',
|
|
|
|
|
- 'Nor',
|
|
|
|
|
- 'As',
|
|
|
|
|
- 'At',
|
|
|
|
|
- 'By',
|
|
|
|
|
- 'For',
|
|
|
|
|
- 'From',
|
|
|
|
|
- 'In',
|
|
|
|
|
- 'Into',
|
|
|
|
|
- 'Near',
|
|
|
|
|
- 'Of',
|
|
|
|
|
- 'On',
|
|
|
|
|
- 'Onto',
|
|
|
|
|
- 'To',
|
|
|
|
|
- 'With',
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ lowers = (settings && settings.titlecase && settings.titlecase.lowers) || [];
|
|
|
for (i = 0, j = lowers.length; i < j; i++)
|
|
for (i = 0, j = lowers.length; i < j; i++)
|
|
|
str = str.replace(new RegExp('\\s' + lowers[i] + '\\s', 'g'), function(txt) {
|
|
str = str.replace(new RegExp('\\s' + lowers[i] + '\\s', 'g'), function(txt) {
|
|
|
return txt.toLowerCase();
|
|
return txt.toLowerCase();
|
|
|
});
|
|
});
|
|
|
// Certain words such as initialisms or acronyms should be left uppercase
|
|
// Certain words such as initialisms or acronyms should be left uppercase
|
|
|
- uppers = ['Id', 'Tv'];
|
|
|
|
|
|
|
+ uppers = (settings && settings.titlecase && settings.titlecase.uppers) || [];
|
|
|
for (i = 0, j = uppers.length; i < j; i++) str = str.replace(new RegExp('\\b' + uppers[i] + '\\b', 'g'), uppers[i].toUpperCase());
|
|
for (i = 0, j = uppers.length; i < j; i++) str = str.replace(new RegExp('\\b' + uppers[i] + '\\b', 'g'), uppers[i].toUpperCase());
|
|
|
return str;
|
|
return str;
|
|
|
};
|
|
};
|
|
@@ -129,8 +109,8 @@ const processOutput = str => {
|
|
|
|
|
|
|
|
const getFilesize = async file => {
|
|
const getFilesize = async file => {
|
|
|
let stats = fs.existsSync(file) ? fs.statSync(file) : false;
|
|
let stats = fs.existsSync(file) ? fs.statSync(file) : false;
|
|
|
- let bytes = (stats) ? stats['size'] : 0;
|
|
|
|
|
- return (bytes && bytes > 0) ? bytes/1024 : 0;
|
|
|
|
|
|
|
+ let bytes = stats ? stats['size'] : 0;
|
|
|
|
|
+ return bytes && bytes > 0 ? bytes / 1024 : 0;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// spawn a handbrake
|
|
// spawn a handbrake
|
|
@@ -239,7 +219,8 @@ const processFile = async file => {
|
|
|
// do we already have an existing output that matches?
|
|
// do we already have an existing output that matches?
|
|
|
if (fs.existsSync(output)) {
|
|
if (fs.existsSync(output)) {
|
|
|
let outputSize = await getFilesize(output); //get output filesize
|
|
let outputSize = await getFilesize(output); //get output filesize
|
|
|
- if (outputSize > 100) { //make sure its bigger than 100k
|
|
|
|
|
|
|
+ if (outputSize > 100) {
|
|
|
|
|
+ //make sure its bigger than 100k
|
|
|
processOutput(` -> "${path.basename(file)}" [skipping] (already processed)\n`);
|
|
processOutput(` -> "${path.basename(file)}" [skipping] (already processed)\n`);
|
|
|
setFile(db, file, {
|
|
setFile(db, file, {
|
|
|
output: output,
|
|
output: output,
|