ssendOnly convert function added
This commit is contained in:
@@ -56,6 +56,9 @@ At first start it will create an empty config file `./novelConfig.conf`, adjust
|
|||||||
// email, intended for completed series archiving
|
// email, intended for completed series archiving
|
||||||
"sendOnly": false, // 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
|
||||||
|
"sendOnlyFormat": "epub" // Format filter for sendOnly files
|
||||||
|
"sendOnlyConvert": true, // Convert sendOnly files, epub => epub is supported,
|
||||||
|
// useful for compressing images in big files
|
||||||
"sendOnlyRegex": ""(?<volume>\\d*). (?<title>.*); (?<author>.*)"" // Metadata regex for extracting
|
"sendOnlyRegex": ""(?<volume>\\d*). (?<title>.*); (?<author>.*)"" // Metadata regex for extracting
|
||||||
// information from filename for external sources
|
// information from filename for external sources
|
||||||
},
|
},
|
||||||
|
|||||||
+27
-12
@@ -95,6 +95,8 @@ async function loadConfig() {
|
|||||||
"completedVolumeChapterCount": 50,
|
"completedVolumeChapterCount": 50,
|
||||||
"redownload": false,
|
"redownload": false,
|
||||||
"sendOnly": false,
|
"sendOnly": false,
|
||||||
|
"sendOnlyFormat": "epub",
|
||||||
|
"sendOnlyConvert": true,
|
||||||
"sendOnlyRegex": "(?<volume>\\d*). (?<title>.*); (?<author>.*)"
|
"sendOnlyRegex": "(?<volume>\\d*). (?<title>.*); (?<author>.*)"
|
||||||
},
|
},
|
||||||
"novels": []
|
"novels": []
|
||||||
@@ -130,18 +132,18 @@ async function saveConfig() {
|
|||||||
await writeFile(__dirname, 'novelConfig.conf', JSON.stringify(config, null, 4));
|
await writeFile(__dirname, 'novelConfig.conf', JSON.stringify(config, null, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function convertEbook(dir, file, params = { "cover": false, "authors": false, "title": false }, format = 'html') {
|
async function convertEbook(dir, file, { cover = false, authors = false, title = false, format = 'html', file2 = false } = {}) {
|
||||||
let file1Path = cleanPath(`${dir}/${file}.${format}`);
|
let file1Path = cleanPath(`${dir}/${file}.${format}`);
|
||||||
let file2Path = cleanPath(`${dir}/${file}.${config['ebookFormat']}`);
|
let file2Path = cleanPath(`${dir}/${file2 ? file2 : file}.${config['ebookFormat']}`);
|
||||||
let convertParams = ' --use-auto-toc';
|
let convertParams = ' --use-auto-toc';
|
||||||
convertParams += config['ebookFormat'] == 'epub' ? ' --epub-inline-toc' : '';
|
convertParams += config['ebookFormat'] == 'epub' ? ' --epub-inline-toc' : '';
|
||||||
convertParams += params['cover'] ? ` --cover "${params['cover']}"` : '';
|
convertParams += cover ? ` --cover "${cover}"` : '';
|
||||||
convertParams += params['authors'] ? ` --authors "${params['authors']}"` : '';
|
convertParams += authors ? ` --authors "${authors}"` : '';
|
||||||
convertParams += params['title'] ? ` --title "${params['title']}"` : '';
|
convertParams += title ? ` --title "${title}"` : '';
|
||||||
|
|
||||||
log(`Converting volume: ${file1Path}`);
|
log(`Converting volume: ${file1Path}`);
|
||||||
|
|
||||||
exec(`${config['converterPath']} "${file1Path}" "${file2Path}"${convertParams}`, (error, stdout, stderr) => {
|
let convertOutput = exec(`${config['converterPath']} "${file1Path}" "${file2Path}"${convertParams}`, function (error, stdout, stderr) {
|
||||||
if (error) {
|
if (error) {
|
||||||
log(`error: ${error.message}`);
|
log(`error: ${error.message}`);
|
||||||
return;
|
return;
|
||||||
@@ -152,6 +154,8 @@ async function convertEbook(dir, file, params = { "cover": false, "authors": fal
|
|||||||
}
|
}
|
||||||
log(`stdout: ${stdout}`);
|
log(`stdout: ${stdout}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log(convertOutput.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -316,7 +320,7 @@ function getChapterContent(response, hosting) {
|
|||||||
async function main() {
|
async function main() {
|
||||||
await loadConfig();
|
await loadConfig();
|
||||||
|
|
||||||
for (let i = 9; 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]);
|
||||||
|
|
||||||
if (novel['redownload']) {
|
if (novel['redownload']) {
|
||||||
@@ -337,7 +341,7 @@ async function main() {
|
|||||||
async function sendOnlyFunction(novel, i) {
|
async function sendOnlyFunction(novel, i) {
|
||||||
let ebookAttachments = [];
|
let ebookAttachments = [];
|
||||||
const novelPath = `${config.downloadLocation}/${novel.title}`;
|
const novelPath = `${config.downloadLocation}/${novel.title}`;
|
||||||
const novelVolumeRegex = new RegExp(novel.sendOnlyRegex);
|
const novelVolumeRegex = new RegExp(novel.sendOnlyRegex + '.' + novel.sendOnlyFormat);
|
||||||
|
|
||||||
let lastVolumeOnline = parseInt(await fetchNovelInfo(novel['novelURL'], 'TNC'));
|
let lastVolumeOnline = parseInt(await fetchNovelInfo(novel['novelURL'], 'TNC'));
|
||||||
|
|
||||||
@@ -351,14 +355,25 @@ async function main() {
|
|||||||
try {
|
try {
|
||||||
const files = await fs.readdir(cleanPath(novelPath));
|
const files = await fs.readdir(cleanPath(novelPath));
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (file.match(new RegExp(config.ebookFormat))) {
|
let volumeMatch = file.match(novelVolumeRegex);
|
||||||
const lastVolume = parseInt(file.match(novelVolumeRegex).groups.volume);
|
if (volumeMatch) {
|
||||||
if (lastVolume > novel.lastVolume) {
|
const currentVolume = parseInt(volumeMatch.groups.volume);
|
||||||
|
if (currentVolume > novel.lastVolume) {
|
||||||
|
if (novel.sendOnlyConvert) {
|
||||||
|
convertEbook(novelPath, path.parse(file).name, { format: novel.sendOnlyFormat, title: `${padNumber(currentVolume, 2)}. ${novel.title}`, file2: `${padNumber(currentVolume, 2)}. ${novel.title}` });
|
||||||
|
|
||||||
|
ebookAttachments.push({
|
||||||
|
filename: cleanPath(`${padNumber(currentVolume, 2)}. ${novel.title}.${config.ebookFormat}`),
|
||||||
|
path: cleanPath(`${novelPath}/${padNumber(currentVolume, 2)}. ${novel.title}.${config.ebookFormat}`)
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
ebookAttachments.push({
|
ebookAttachments.push({
|
||||||
filename: cleanPath(`${file}`),
|
filename: cleanPath(`${file}`),
|
||||||
path: cleanPath(`${novelPath}/${file}`)
|
path: cleanPath(`${novelPath}/${file}`)
|
||||||
});
|
});
|
||||||
novel.lastVolume = lastVolume;
|
}
|
||||||
|
novel.lastVolume = currentVolume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user