sendOnly implemented
This commit is contained in:
@@ -54,10 +54,10 @@ At first start it will create an empty config file `./novelConfig.conf`, adjust
|
|||||||
"completedVolumeChapterCount": 50, // How many chapters to pack per eBook
|
"completedVolumeChapterCount": 50, // How many chapters to pack per eBook
|
||||||
"redownload": false // Redownload all chapters, repack into volumes, do not send via
|
"redownload": false // Redownload all chapters, repack into volumes, do not send via
|
||||||
// email, intended for completed series archiving
|
// email, intended for completed series archiving
|
||||||
"sendOnly": false, // TODO: only send epub files via email, for cases with external
|
"sendOnly": false, // Only send epub files via email, for cases with external
|
||||||
// source of epub files
|
// source of epub files
|
||||||
"sendOnlyRegex": ""(?<volume>\\d*). (?<title>.*); (?<author>.*)"" // TODO: metadata regex for
|
"sendOnlyRegex": ""(?<volume>\\d*). (?<title>.*); (?<author>.*)"" // Metadata regex for extracting
|
||||||
// extracting information from filename for external sources
|
// information from filename for external sources
|
||||||
},
|
},
|
||||||
"novels": [
|
"novels": [
|
||||||
// Table of novels to process, insert the template structure
|
// Table of novels to process, insert the template structure
|
||||||
|
|||||||
+66
-19
@@ -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(`./WNtoEmail.log`), `${dateTime} ${text}\n`);
|
fs.appendFile(cleanPath(`./WNtoEmail.log`), `${dateTime} ${text}\n`);
|
||||||
|
console.log(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mkDir(dirPath) {
|
async function mkDir(dirPath) {
|
||||||
@@ -93,8 +94,8 @@ async function loadConfig() {
|
|||||||
"volumeChapterCount": 5,
|
"volumeChapterCount": 5,
|
||||||
"completedVolumeChapterCount": 50,
|
"completedVolumeChapterCount": 50,
|
||||||
"redownload": false,
|
"redownload": false,
|
||||||
"sendOnly": false, // TODO: only send epub files via email, for cases with external source of epub files or after "redownload"
|
"sendOnly": false,
|
||||||
"sendOnlyRegex": "(?<volume>\\d*). (?<title>.*); (?<author>.*)" // TODO: metadata regex for extracting information from filename for external sources
|
"sendOnlyRegex": "(?<volume>\\d*). (?<title>.*); (?<author>.*)"
|
||||||
},
|
},
|
||||||
"novels": []
|
"novels": []
|
||||||
};
|
};
|
||||||
@@ -138,21 +139,17 @@ async function convertEbook(dir, file, params = { "cover": false, "authors": fal
|
|||||||
convertParams += params['authors'] ? ` --authors "${params['authors']}"` : '';
|
convertParams += params['authors'] ? ` --authors "${params['authors']}"` : '';
|
||||||
convertParams += params['title'] ? ` --title "${params['title']}"` : '';
|
convertParams += params['title'] ? ` --title "${params['title']}"` : '';
|
||||||
|
|
||||||
console.log(`Converting volume: ${file1Path}`);
|
|
||||||
log(`Converting volume: ${file1Path}`);
|
log(`Converting volume: ${file1Path}`);
|
||||||
|
|
||||||
exec(`${config['converterPath']} "${file1Path}" "${file2Path}"${convertParams}`, (error, stdout, stderr) => {
|
exec(`${config['converterPath']} "${file1Path}" "${file2Path}"${convertParams}`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(`error: ${error.message}`);
|
|
||||||
log(`error: ${error.message}`);
|
log(`error: ${error.message}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.log(`stderr: ${stderr}`);
|
|
||||||
log(`stderr: ${stderr}`);
|
log(`stderr: ${stderr}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`stdout: ${stdout}`);
|
|
||||||
log(`stdout: ${stdout}`);
|
log(`stdout: ${stdout}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -179,13 +176,12 @@ function sendEbook(subject, ebookAttachments) {
|
|||||||
|
|
||||||
transporter.sendMail(message, (err) => {
|
transporter.sendMail(message, (err) => {
|
||||||
if (err)
|
if (err)
|
||||||
console.log(err);
|
log(`Send mail error: ${err}`);
|
||||||
log(err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Sent volumes:`);
|
let sentVolumes = '';
|
||||||
log(`Sent volumes:`);
|
splicedAttachments[i].forEach(elem => { sentVolumes += '\n' + elem['filename']; });
|
||||||
splicedAttachments[i].forEach(elem => console.log(elem['filename']));
|
log(`Sent volumes:${sentVolumes}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,6 +259,15 @@ async function getNovelInfo(response, hosting) {
|
|||||||
info = [title, author, completed, 'https://novelfull.com' + firstChapterURL, 'https://novelfull.com' + coverURL];
|
info = [title, author, completed, 'https://novelfull.com' + firstChapterURL, 'https://novelfull.com' + coverURL];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'TNC':
|
||||||
|
html.querySelectorAll('a').forEach(elem => {
|
||||||
|
if (elem.innerText.match('Volume')) {
|
||||||
|
info = elem.innerText.match(/\d+/)[0];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
info = false;
|
info = false;
|
||||||
}
|
}
|
||||||
@@ -311,10 +316,8 @@ function getChapterContent(response, hosting) {
|
|||||||
async function main() {
|
async function main() {
|
||||||
await loadConfig();
|
await loadConfig();
|
||||||
|
|
||||||
for (let i = 0; i < config['novels'].length; ++i) {
|
for (let i = 9; i < config['novels'].length; ++i) {
|
||||||
let novel = clone(config['novels'][i]);
|
let novel = clone(config['novels'][i]);
|
||||||
let chapters = [];
|
|
||||||
let nextChapterURL;
|
|
||||||
|
|
||||||
if (novel['redownload']) {
|
if (novel['redownload']) {
|
||||||
novel['completed'] = false;
|
novel['completed'] = false;
|
||||||
@@ -323,6 +326,55 @@ async function main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!novel['completed']) {
|
if (!novel['completed']) {
|
||||||
|
if (novel.sendOnly) {
|
||||||
|
await sendOnlyFunction(novel, i);
|
||||||
|
} else {
|
||||||
|
await downloadChaptersFunction(novel, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendOnlyFunction(novel, i) {
|
||||||
|
let ebookAttachments = [];
|
||||||
|
const novelPath = `${config.downloadLocation}/${novel.title}`;
|
||||||
|
const novelVolumeRegex = new RegExp(novel.sendOnlyRegex);
|
||||||
|
|
||||||
|
let lastVolumeOnline = parseInt(await fetchNovelInfo(novel['novelURL'], 'TNC'));
|
||||||
|
|
||||||
|
if (lastVolumeOnline > novel.lastVolume) {
|
||||||
|
log(`New volume found online: ${novel.title} ${lastVolumeOnline}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// let ebookList = await fs.opendir(cleanPath(novelPath));
|
||||||
|
// console.log(ebookList);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const files = await fs.readdir(cleanPath(novelPath));
|
||||||
|
for (const file of files) {
|
||||||
|
if (file.match(new RegExp(config.ebookFormat))) {
|
||||||
|
const lastVolume = parseInt(file.match(novelVolumeRegex).groups.volume);
|
||||||
|
if (lastVolume > novel.lastVolume) {
|
||||||
|
ebookAttachments.push({
|
||||||
|
filename: cleanPath(`${file}`),
|
||||||
|
path: cleanPath(`${novelPath}/${file}`)
|
||||||
|
});
|
||||||
|
novel.lastVolume = lastVolume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
config['novels'][i] = clone(novel);
|
||||||
|
await saveConfig();
|
||||||
|
|
||||||
|
sendEbook(novel['title'], ebookAttachments);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadChaptersFunction(novel, i) {
|
||||||
|
let chapters = [];
|
||||||
|
let nextChapterURL;
|
||||||
let novelInfo = await fetchNovelInfo(novel['novelURL'], 'NF');
|
let novelInfo = await fetchNovelInfo(novel['novelURL'], 'NF');
|
||||||
|
|
||||||
novel['title'] = novelInfo[0];
|
novel['title'] = novelInfo[0];
|
||||||
@@ -337,7 +389,6 @@ async function main() {
|
|||||||
novel['lastChapterURL'] = novelInfo[3];
|
novel['lastChapterURL'] = novelInfo[3];
|
||||||
|
|
||||||
let chapter = await fetchChapter(novelInfo[3], 'NF');
|
let chapter = await fetchChapter(novelInfo[3], 'NF');
|
||||||
console.log('Downloaded chapter: ' + chapters.length + ' ' + novelInfo[3]);
|
|
||||||
log('Downloaded chapter: ' + chapters.length + ' ' + novelInfo[3]);
|
log('Downloaded chapter: ' + chapters.length + ' ' + novelInfo[3]);
|
||||||
chapters.push(chapter);
|
chapters.push(chapter);
|
||||||
}
|
}
|
||||||
@@ -350,7 +401,6 @@ async function main() {
|
|||||||
while (nextChapterURL) {
|
while (nextChapterURL) {
|
||||||
novel['lastChapterURL'] = nextChapterURL;
|
novel['lastChapterURL'] = nextChapterURL;
|
||||||
let chapter = await fetchChapter(nextChapterURL, 'NF');
|
let chapter = await fetchChapter(nextChapterURL, 'NF');
|
||||||
console.log('Downloaded chapter: ' + chapters.length + ' ' + nextChapterURL);
|
|
||||||
log('Downloaded chapter: ' + chapters.length + ' ' + nextChapterURL);
|
log('Downloaded chapter: ' + chapters.length + ' ' + nextChapterURL);
|
||||||
chapters.push(chapter);
|
chapters.push(chapter);
|
||||||
nextChapterURL = chapter[1];
|
nextChapterURL = chapter[1];
|
||||||
@@ -381,7 +431,6 @@ async function main() {
|
|||||||
let novelFileName = `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}; ${novel['author']}`;
|
let novelFileName = `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}; ${novel['author']}`;
|
||||||
|
|
||||||
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
||||||
console.log(`Saved volume: ${novelFileName}`);
|
|
||||||
log(`Saved volume: ${novelFileName}`);
|
log(`Saved volume: ${novelFileName}`);
|
||||||
|
|
||||||
await convertEbook(novelDir, novelFileName, {
|
await convertEbook(novelDir, novelFileName, {
|
||||||
@@ -417,7 +466,6 @@ async function main() {
|
|||||||
let novelFileName = `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}; ${novel['author']}`;
|
let novelFileName = `${padNumber((vol + 1), maxVolLen)}. ${novel['title']}; ${novel['author']}`;
|
||||||
|
|
||||||
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
await writeFile(novelDir, `${novelFileName}.html`, volContent);
|
||||||
console.log(`Saved volume: ${novelFileName}`);
|
|
||||||
log(`Saved volume: ${novelFileName}`);
|
log(`Saved volume: ${novelFileName}`);
|
||||||
|
|
||||||
await convertEbook(novelDir, novelFileName, {
|
await convertEbook(novelDir, novelFileName, {
|
||||||
@@ -443,6 +491,5 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
main();
|
||||||
Reference in New Issue
Block a user