fixes
This commit is contained in:
+61
-29
@@ -40,6 +40,7 @@ function log(text) {
|
|||||||
let d = new Date();
|
let d = new Date();
|
||||||
let dateTime = `${d.getFullYear()}.${padNumber((d.getMonth() + 1), 2)}.${padNumber(d.getDate(), 2)}_${padNumber(d.getHours(), 2)}:${padNumber(d.getMinutes(), 2)}:${padNumber(d.getSeconds(), 2)}.${padNumber(d.getMilliseconds(), 3)}`;
|
let dateTime = `${d.getFullYear()}.${padNumber((d.getMonth() + 1), 2)}.${padNumber(d.getDate(), 2)}_${padNumber(d.getHours(), 2)}:${padNumber(d.getMinutes(), 2)}:${padNumber(d.getSeconds(), 2)}.${padNumber(d.getMilliseconds(), 3)}`;
|
||||||
fs.appendFile(cleanPath(`${__dirname}/WNtoEmail.log`), `${dateTime} ${text}\n`);
|
fs.appendFile(cleanPath(`${__dirname}/WNtoEmail.log`), `${dateTime} ${text}\n`);
|
||||||
|
fs.appendFile(cleanPath(`${__dirname}/WNtoEmailArch.log`), `${dateTime} ${text}\n`);
|
||||||
console.log(text);
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ async function loadConfig() {
|
|||||||
"converterPath": "ebook-convert.exe",
|
"converterPath": "ebook-convert.exe",
|
||||||
"ebookFormat": "epub",
|
"ebookFormat": "epub",
|
||||||
"sendEmail": false,
|
"sendEmail": false,
|
||||||
|
"copyPath": "",
|
||||||
"emailToAddress": "",
|
"emailToAddress": "",
|
||||||
"emailFromAddress": "",
|
"emailFromAddress": "",
|
||||||
"emailProvider": "",
|
"emailProvider": "",
|
||||||
@@ -80,7 +82,8 @@ async function loadConfig() {
|
|||||||
"emailAttachments": 25,
|
"emailAttachments": 25,
|
||||||
"supportedHosting": {
|
"supportedHosting": {
|
||||||
"NF": "https://novelfull.com/",
|
"NF": "https://novelfull.com/",
|
||||||
"TNC": "https://thatnovelcorner.com/ external source, use with sendOnly = true"
|
"TNC": "https://thatnovelcorner.com/ external source, use with sendOnly = true",
|
||||||
|
"BBB": "https://bluebellsinbloom.wordpress.com/",
|
||||||
},
|
},
|
||||||
"template": {
|
"template": {
|
||||||
"novelURL": "",
|
"novelURL": "",
|
||||||
@@ -89,10 +92,11 @@ async function loadConfig() {
|
|||||||
"coverURL": "",
|
"coverURL": "",
|
||||||
"lastChapterURL": "",
|
"lastChapterURL": "",
|
||||||
"lastVolume": 0,
|
"lastVolume": 0,
|
||||||
|
"volumePadding": 2,
|
||||||
"completed": false,
|
"completed": false,
|
||||||
"hosting": "NF",
|
"hosting": "NF",
|
||||||
"volumeChapterCount": 5,
|
"volumeChapterCount": 5,
|
||||||
"completedVolumeChapterCount": 50,
|
"completedVolumeChapterCount": 200,
|
||||||
"redownload": false,
|
"redownload": false,
|
||||||
"sendOnly": false,
|
"sendOnly": false,
|
||||||
"sendOnlyFormat": "epub",
|
"sendOnlyFormat": "epub",
|
||||||
@@ -104,21 +108,34 @@ async function loadConfig() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
config = JSON.parse(await readFile(`${__dirname}/novelConfig.json`));
|
config = JSON.parse(await readFile(`${__dirname}/novelConfig.json`));
|
||||||
transporter = nodemailer.createTransport({
|
|
||||||
service: config['emailProvider'],
|
for (key in novelConfigDefault) {
|
||||||
auth: {
|
if (config[key] == undefined) {
|
||||||
user: config['emailUsername'],
|
config[key] = clone(novelConfigDefault[key]);
|
||||||
pass: config['emailPassword']
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
await writeFile('__dirname', 'novelConfig.json', JSON.stringify(config, null, 4));
|
|
||||||
await writeFile('__dirname', 'novelConfig.bak.json', JSON.stringify(config, null, 4));
|
for (key in novelConfigDefault['template']) {
|
||||||
|
if (config['template'][key] == undefined) {
|
||||||
|
config['template'][key] = clone(novelConfigDefault['template'][key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < config['novels'].length; ++i) {
|
||||||
|
for (key in novelConfigDefault['template']) {
|
||||||
|
if (config['novels'][i][key] == undefined) {
|
||||||
|
config['novels'][i][key] = clone(novelConfigDefault['template'][key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
await writeFile('__dirname', 'novelConfig.json', JSON.stringify(novelConfigDefault, null, 4));
|
config = clone(novelConfigDefault);
|
||||||
config = novelConfigDefault;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await saveConfig();
|
||||||
|
await saveConfig({ configName: 'novelConfig.bak.json' });
|
||||||
|
|
||||||
transporter = nodemailer.createTransport({
|
transporter = nodemailer.createTransport({
|
||||||
service: config['emailProvider'],
|
service: config['emailProvider'],
|
||||||
auth: {
|
auth: {
|
||||||
@@ -128,8 +145,8 @@ async function loadConfig() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveConfig() {
|
async function saveConfig({ configPath = __dirname, configName = 'novelConfig.json' } = {}) {
|
||||||
await writeFile(__dirname, 'novelConfig.json', JSON.stringify(config, null, 4));
|
await writeFile(configPath, configName, JSON.stringify(config, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function convertEbook(dir, file, { cover = false, authors = false, title = false, format = 'html', file2 = false } = {}) {
|
async function convertEbook(dir, file, { cover = false, authors = false, title = false, format = 'html', file2 = false } = {}) {
|
||||||
@@ -158,8 +175,7 @@ async function convertEbook(dir, file, { cover = false, authors = false, title =
|
|||||||
log(convertOutput.toString());
|
log(convertOutput.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendEbook(subject, ebookAttachments) {
|
||||||
function sendEbook(subject, ebookAttachments) {
|
|
||||||
if (config['sendEmail']) {
|
if (config['sendEmail']) {
|
||||||
let splicedAttachments = [];
|
let splicedAttachments = [];
|
||||||
while (ebookAttachments.length > config['emailAttachments']) {
|
while (ebookAttachments.length > config['emailAttachments']) {
|
||||||
@@ -188,6 +204,12 @@ function sendEbook(subject, ebookAttachments) {
|
|||||||
log(`Sent volumes:${sentVolumes}`);
|
log(`Sent volumes:${sentVolumes}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (config['copyPath'] != "") {
|
||||||
|
for (const ebook of ebookAttachments) {
|
||||||
|
await mkDir(`${config.copyPath}\\${ebook.title}`);
|
||||||
|
fs.copyFile(ebook.path, cleanPath(`${config.copyPath}\\${ebook.title}\\${ebook.filename}`),);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetch_something(URL, hosting) {
|
async function fetch_something(URL, hosting) {
|
||||||
@@ -317,8 +339,13 @@ function getChapterContent(response, hosting) {
|
|||||||
return chapterContent;
|
return chapterContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function clearLog() {
|
||||||
|
await writeFile(`${__dirname}`, `WNtoEmail.log`, '');
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
await loadConfig();
|
await loadConfig();
|
||||||
|
await clearLog()
|
||||||
|
|
||||||
for (let i = 0; i < config['novels'].length; ++i) {
|
for (let i = 0; i < config['novels'].length; ++i) {
|
||||||
let novel = clone(config['novels'][i]);
|
let novel = clone(config['novels'][i]);
|
||||||
@@ -360,15 +387,17 @@ async function main() {
|
|||||||
const currentVolume = parseInt(volumeMatch.groups.volume);
|
const currentVolume = parseInt(volumeMatch.groups.volume);
|
||||||
if (currentVolume > novel.lastVolume) {
|
if (currentVolume > novel.lastVolume) {
|
||||||
if (novel.sendOnlyConvert) {
|
if (novel.sendOnlyConvert) {
|
||||||
convertEbook(novelPath, path.parse(file).name, { format: novel.sendOnlyFormat, title: `${padNumber(currentVolume, 2)}. ${novel.title}`, file2: `${padNumber(currentVolume, 2)}. ${novel.title}` });
|
convertEbook(novelPath, path.parse(file).name, { format: novel.sendOnlyFormat, title: `${padNumber(currentVolume, novel.volumePadding)}. ${novel.title}`, file2: `${padNumber(currentVolume, novel.volumePadding)}. ${novel.title}` });
|
||||||
|
|
||||||
ebookAttachments.push({
|
ebookAttachments.push({
|
||||||
filename: cleanPath(`${padNumber(currentVolume, 2)}. ${novel.title}.${config.ebookFormat}`),
|
title: novel.title,
|
||||||
path: cleanPath(`${novelPath}/${padNumber(currentVolume, 2)}. ${novel.title}.${config.ebookFormat}`)
|
filename: cleanPath(`${padNumber(currentVolume, novel.volumePadding)}. ${novel.title}.${config.ebookFormat}`),
|
||||||
|
path: cleanPath(`${novelPath}/${padNumber(currentVolume, novel.volumePadding)}. ${novel.title}.${config.ebookFormat}`)
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ebookAttachments.push({
|
ebookAttachments.push({
|
||||||
|
title: novel.title,
|
||||||
filename: cleanPath(`${file}`),
|
filename: cleanPath(`${file}`),
|
||||||
path: cleanPath(`${novelPath}/${file}`)
|
path: cleanPath(`${novelPath}/${file}`)
|
||||||
});
|
});
|
||||||
@@ -424,13 +453,13 @@ async function main() {
|
|||||||
let startVol = novel['lastVolume'];
|
let startVol = novel['lastVolume'];
|
||||||
let totalChapters = chapters.length;
|
let totalChapters = chapters.length;
|
||||||
|
|
||||||
const maxVolume = novel['completed'] ? startVol + Math.ceil(totalChapters / novel['completedVolumeChapterCount']) : startVol + Math.floor(totalChapters / novel['completedVolumeChapterCount']);
|
const maxVolumeComplete = novel['completed'] ? startVol + Math.ceil(totalChapters / novel['completedVolumeChapterCount']) : startVol + Math.floor(totalChapters / novel['completedVolumeChapterCount']);
|
||||||
const maxVolLen = (novel['completed'] ? maxVolume :
|
const maxVolumeUpdate = novel['completed'] ? 0 : 1;// ? maxVolumeComplete : maxVolumeComplete + Math.floor((totalChapters - ((maxVolumeComplete - startVol) * novel.completedVolumeChapterCount)) / novel['volumeChapterCount'])
|
||||||
maxVolume + Math.floor((chapters.length - (maxVolume * novel['completedVolumeChapterCount'])) / novel['volumeChapterCount'])).toString().length;
|
const maxVolLen = novel['volumePadding'] ? novel['volumePadding'] : (maxVolumeUpdate.toString().length < 2 ? 2 : maxVolumeUpdate.toString().length);
|
||||||
|
|
||||||
let ebookAttachments = [];
|
let ebookAttachments = [];
|
||||||
|
|
||||||
for (let vol = startVol; vol < maxVolume; vol++) {
|
for (let vol = startVol; vol < maxVolumeComplete; vol++) {
|
||||||
let volContent = '';
|
let volContent = '';
|
||||||
|
|
||||||
let chap;
|
let chap;
|
||||||
@@ -443,7 +472,7 @@ async function main() {
|
|||||||
config['novels'][i] = clone(novel);
|
config['novels'][i] = clone(novel);
|
||||||
await saveConfig();
|
await saveConfig();
|
||||||
|
|
||||||
let novelFileName = `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}; ${novel['author']}`;
|
let novelFileName = `${padNumber((vol + 1), novel.volumePadding)}. ${novel['title']}; ${novel['author']}`;
|
||||||
|
|
||||||
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
||||||
log(`Saved volume: ${novelFileName}`);
|
log(`Saved volume: ${novelFileName}`);
|
||||||
@@ -451,10 +480,11 @@ async function main() {
|
|||||||
await convertEbook(novelDir, novelFileName, {
|
await convertEbook(novelDir, novelFileName, {
|
||||||
cover: novel['coverURL'],
|
cover: novel['coverURL'],
|
||||||
authors: novel['author'],
|
authors: novel['author'],
|
||||||
title: `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}`
|
title: `${padNumber((vol + 1), novel.volumePadding)}. ${novel['title']}`
|
||||||
});
|
});
|
||||||
|
|
||||||
ebookAttachments.push({
|
ebookAttachments.push({
|
||||||
|
title: novel.title,
|
||||||
filename: cleanPath(`${novelFileName}.${config['ebookFormat']}`),
|
filename: cleanPath(`${novelFileName}.${config['ebookFormat']}`),
|
||||||
path: cleanPath(`${novelDir}/${novelFileName}.${config['ebookFormat']}`)
|
path: cleanPath(`${novelDir}/${novelFileName}.${config['ebookFormat']}`)
|
||||||
});
|
});
|
||||||
@@ -465,11 +495,12 @@ async function main() {
|
|||||||
startVol = novel['lastVolume'];
|
startVol = novel['lastVolume'];
|
||||||
totalChapters = chapters.length;
|
totalChapters = chapters.length;
|
||||||
|
|
||||||
for (let vol = startVol; vol < startVol + Math.floor(totalChapters / novel['volumeChapterCount']); vol++) {
|
if (maxVolumeUpdate && totalChapters >= novel.volumeChapterCount) {
|
||||||
|
let vol = maxVolumeComplete;
|
||||||
let volContent = '';
|
let volContent = '';
|
||||||
|
|
||||||
let chap;
|
let chap;
|
||||||
for (chap = 0; chap < novel['volumeChapterCount'] && chap < chapters.length; chap++) {
|
for (chap = 0; chap < Math.floor(totalChapters / novel.volumeChapterCount) * novel.volumeChapterCount; chap++) {
|
||||||
volContent += chapters[chap][0] + '\n';
|
volContent += chapters[chap][0] + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +509,7 @@ async function main() {
|
|||||||
config['novels'][i] = clone(novel);
|
config['novels'][i] = clone(novel);
|
||||||
await saveConfig();
|
await saveConfig();
|
||||||
|
|
||||||
let novelFileName = `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}; ${novel['author']}`;
|
let novelFileName = `${padNumber((vol + 1), novel.volumePadding)}. ${novel['title']}; ${novel['author']}`;
|
||||||
|
|
||||||
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
||||||
log(`Saved volume: ${novelFileName}`);
|
log(`Saved volume: ${novelFileName}`);
|
||||||
@@ -486,10 +517,11 @@ async function main() {
|
|||||||
await convertEbook(novelDir, novelFileName, {
|
await convertEbook(novelDir, novelFileName, {
|
||||||
cover: novel['coverURL'],
|
cover: novel['coverURL'],
|
||||||
authors: novel['author'],
|
authors: novel['author'],
|
||||||
title: `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}`
|
title: `${padNumber((vol + 1), novel.volumePadding)}. ${novel['title']}`
|
||||||
});
|
});
|
||||||
|
|
||||||
ebookAttachments.push({
|
ebookAttachments.push({
|
||||||
|
title: novel.title,
|
||||||
filename: cleanPath(`${novelFileName}.${config['ebookFormat']}`),
|
filename: cleanPath(`${novelFileName}.${config['ebookFormat']}`),
|
||||||
path: cleanPath(`${novelDir}/${novelFileName}.${config['ebookFormat']}`)
|
path: cleanPath(`${novelDir}/${novelFileName}.${config['ebookFormat']}`)
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user