2024-01-08 00:51:07 +01:00
|
|
|
const parseEpubMetadata = require('./parseEpubMetadata')
|
2024-01-15 00:51:26 +01:00
|
|
|
const parseComicMetadata = require('./parseComicMetadata')
|
2024-01-08 00:51:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef EBookFileScanData
|
|
|
|
* @property {string} path
|
|
|
|
* @property {string} ebookFormat
|
|
|
|
* @property {string} ebookCoverPath internal image path
|
|
|
|
* @property {import('../../scanner/BookScanner').BookMetadataObject} metadata
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse metadata from ebook file
|
|
|
|
*
|
|
|
|
* @param {import('../../models/Book').EBookFileObject} ebookFile
|
|
|
|
* @returns {Promise<EBookFileScanData>}
|
|
|
|
*/
|
|
|
|
async function parse(ebookFile) {
|
|
|
|
if (!ebookFile) return null
|
|
|
|
|
|
|
|
if (ebookFile.ebookFormat === 'epub') {
|
2024-01-15 00:51:26 +01:00
|
|
|
return parseEpubMetadata.parse(ebookFile)
|
|
|
|
} else if (['cbz', 'cbr'].includes(ebookFile.ebookFormat)) {
|
|
|
|
return parseComicMetadata.parse(ebookFile)
|
2024-01-08 00:51:07 +01:00
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
module.exports.parse = parse
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract cover from ebook file
|
|
|
|
*
|
|
|
|
* @param {EBookFileScanData} ebookFileScanData
|
|
|
|
* @param {string} outputCoverPath
|
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
async function extractCoverImage(ebookFileScanData, outputCoverPath) {
|
|
|
|
if (!ebookFileScanData?.ebookCoverPath) return false
|
|
|
|
|
|
|
|
if (ebookFileScanData.ebookFormat === 'epub') {
|
|
|
|
return parseEpubMetadata.extractCoverImage(ebookFileScanData.path, ebookFileScanData.ebookCoverPath, outputCoverPath)
|
2024-01-15 00:51:26 +01:00
|
|
|
} else if (['cbz', 'cbr'].includes(ebookFileScanData.ebookFormat)) {
|
|
|
|
return parseComicMetadata.extractCoverImage(ebookFileScanData.path, ebookFileScanData.ebookCoverPath, outputCoverPath)
|
2024-01-08 00:51:07 +01:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
module.exports.extractCoverImage = extractCoverImage
|