mirror of
https://github.com/YACReader/yacreader
synced 2025-05-25 18:00:46 -04:00
Use InitialComicInfoExtractor everywhere
This commit is contained in:
parent
2bebe9714e
commit
da51bd45c6
@ -1,12 +1,14 @@
|
||||
#include "data_base_management.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include "library_creator.h"
|
||||
#include "initial_comic_info_extractor.h"
|
||||
#include "check_new_version.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
#include "QsLog.h"
|
||||
|
||||
using namespace YACReader;
|
||||
|
||||
static QString fields = "title ,"
|
||||
|
||||
"coverPage,"
|
||||
@ -543,8 +545,8 @@ bool DataBaseManagement::importComicsInfo(QString source, QString dest)
|
||||
QString basePath = QString(dest).remove("/.yacreaderlibrary/library.ydb");
|
||||
QString path = basePath + getComic.record().value("path").toString();
|
||||
int coverPage = getComic.record().value("coverPage").toInt();
|
||||
ThumbnailCreator tc(path, basePath + "/.yacreaderlibrary/covers/" + hash + ".jpg", coverPage);
|
||||
tc.create();
|
||||
InitialComicInfoExtractor ie(path, basePath + "/.yacreaderlibrary/covers/" + hash + ".jpg", coverPage);
|
||||
ie.extract();
|
||||
}
|
||||
}
|
||||
sourceDBconnection = sourceDB.connectionName();
|
||||
|
@ -12,7 +12,8 @@
|
||||
#include "qnaturalsorting.h"
|
||||
#include "db_helper.h"
|
||||
|
||||
#include "compressed_archive.h"
|
||||
#include "initial_comic_info_extractor.h"
|
||||
#include "xml_info_parser.h"
|
||||
#include "comic.h"
|
||||
#include "pdf_comic.h"
|
||||
#include "yacreader_global.h"
|
||||
@ -20,7 +21,9 @@
|
||||
#include "QsLog.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace YACReader;
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
LibraryCreator::LibraryCreator()
|
||||
@ -173,6 +176,7 @@ void LibraryCreator::run()
|
||||
return;
|
||||
}
|
||||
QSqlQuery pragma("PRAGMA foreign_keys = ON", _database);
|
||||
pragma.exec();
|
||||
_database.transaction();
|
||||
|
||||
if (partialUpdate) {
|
||||
@ -295,11 +299,13 @@ void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &f
|
||||
int numPages = 0;
|
||||
QPair<int, int> originalCoverSize = { 0, 0 };
|
||||
bool exists = checkCover(hash);
|
||||
|
||||
YACReader::InitialComicInfoExtractor ie(QDir::cleanPath(fileInfo.absoluteFilePath()), _target + "/covers/" + hash + ".jpg", comic.info.coverPage.toInt());
|
||||
|
||||
if (!(comic.hasCover() && exists)) {
|
||||
ThumbnailCreator tc(QDir::cleanPath(fileInfo.absoluteFilePath()), _target + "/covers/" + hash + ".jpg", comic.info.coverPage.toInt());
|
||||
tc.create();
|
||||
numPages = tc.getNumPages();
|
||||
originalCoverSize = tc.getOriginalCoverSize();
|
||||
ie.extract();
|
||||
numPages = ie.getNumPages();
|
||||
originalCoverSize = ie.getOriginalCoverSize();
|
||||
if (numPages > 0) {
|
||||
emit(comicAdded(relativePath, _target + "/covers/" + hash + ".jpg"));
|
||||
}
|
||||
@ -308,6 +314,9 @@ void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &f
|
||||
if (numPages > 0 || exists) {
|
||||
//en este punto sabemos que todos los folders que hay en _currentPath, deberían estar añadidos a la base de datos
|
||||
insertFolders();
|
||||
|
||||
bool parsed = YACReader::parseXMLIntoInfo(ie.getXMLInfoRawData(), comic.info);
|
||||
|
||||
comic.info.numPages = numPages;
|
||||
if (originalCoverSize.second > 0) {
|
||||
comic.info.originalCoverSize = QString("%1x%2").arg(originalCoverSize.first).arg(originalCoverSize.second);
|
||||
@ -316,7 +325,8 @@ void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &f
|
||||
|
||||
comic.parentId = _currentPathFolders.last().id;
|
||||
comic.info.manga = _currentPathFolders.last().isManga();
|
||||
DBHelper::insert(&comic, _database);
|
||||
|
||||
DBHelper::insert(&comic, _database, parsed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -539,143 +549,3 @@ void LibraryCreator::update(QDir dirS)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ThumbnailCreator::crash = false;
|
||||
|
||||
ThumbnailCreator::ThumbnailCreator(QString fileSource, QString target, int coverPage)
|
||||
: _fileSource(fileSource), _target(target), _numPages(0), _coverPage(coverPage)
|
||||
{
|
||||
}
|
||||
|
||||
void ThumbnailCreator::create()
|
||||
{
|
||||
QFileInfo fi(_fileSource);
|
||||
if (!fi.exists()) //TODO: error file not found.
|
||||
{
|
||||
_cover.load(":/images/notCover.png");
|
||||
QLOG_WARN() << "Extracting cover: file not found " << _fileSource;
|
||||
return;
|
||||
}
|
||||
#ifndef NO_PDF
|
||||
if (fi.suffix().compare("pdf", Qt::CaseInsensitive) == 0) {
|
||||
#if defined Q_OS_MAC && defined USE_PDFKIT
|
||||
MacOSXPDFComic *pdfComic = new MacOSXPDFComic();
|
||||
if (!pdfComic->openComic(_fileSource)) {
|
||||
delete pdfComic;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
#elif defined USE_PDFIUM
|
||||
auto pdfComic = new PdfiumComic();
|
||||
if (!pdfComic->openComic(_fileSource)) {
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
Poppler::Document *pdfComic = Poppler::Document::load(_fileSource);
|
||||
#endif
|
||||
|
||||
if (!pdfComic) {
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
//delete pdfComic; //TODO check if the delete is needed
|
||||
pdfComic = 0;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
return;
|
||||
}
|
||||
#if !defined USE_PDFKIT && !defined USE_PDFIUM
|
||||
//poppler only, not mac
|
||||
if (pdfComic->isLocked()) {
|
||||
QLOG_WARN() << "Extracting cover: unable to open PDF file " << _fileSource;
|
||||
delete pdfComic;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
_numPages = pdfComic->numPages();
|
||||
if (_numPages >= _coverPage) {
|
||||
#if defined Q_OS_MAC || defined USE_PDFIUM
|
||||
QImage p = pdfComic->getPage(_coverPage - 1); //TODO check if the page is valid
|
||||
#else
|
||||
QImage p = pdfComic->page(_coverPage - 1)->renderToImage(72, 72);
|
||||
#endif //
|
||||
_cover = p;
|
||||
_coverSize = QPair<int, int>(p.width(), p.height());
|
||||
if (_target != "") {
|
||||
QImage scaled;
|
||||
if (p.width() > p.height()) //landscape??
|
||||
{
|
||||
scaled = p.scaledToWidth(640, Qt::SmoothTransformation);
|
||||
} else {
|
||||
scaled = p.scaledToWidth(480, Qt::SmoothTransformation);
|
||||
}
|
||||
scaled.save(_target, 0, 75);
|
||||
} else if (_target != "") {
|
||||
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
|
||||
//QImage p;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
delete pdfComic;
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif //NO_PDF
|
||||
|
||||
if (crash) {
|
||||
return;
|
||||
}
|
||||
|
||||
CompressedArchive archive(_fileSource);
|
||||
if (!archive.toolsLoaded()) {
|
||||
QLOG_WARN() << "Extracting cover: 7z lib not loaded";
|
||||
crash = true;
|
||||
return;
|
||||
}
|
||||
if (!archive.isValid()) {
|
||||
QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource;
|
||||
}
|
||||
//se filtran para obtener sólo los formatos soportados
|
||||
QList<QString> order = archive.getFileNames();
|
||||
QList<QString> fileNames = FileComic::filter(order);
|
||||
_numPages = fileNames.size();
|
||||
if (_numPages == 0) {
|
||||
QLOG_WARN() << "Extracting cover: empty comic " << _fileSource;
|
||||
_cover.load(":/images/notCover.png");
|
||||
if (_target != "") {
|
||||
_cover.save(_target);
|
||||
}
|
||||
} else {
|
||||
if (_coverPage > _numPages) {
|
||||
_coverPage = 1;
|
||||
}
|
||||
std::sort(fileNames.begin(), fileNames.end(), naturalSortLessThanCI);
|
||||
int index = order.indexOf(fileNames.at(_coverPage - 1));
|
||||
|
||||
if (_target == "") {
|
||||
if (!_cover.loadFromData(archive.getRawDataAtIndex(index))) {
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
_cover.load(":/images/notCover.png");
|
||||
}
|
||||
} else {
|
||||
QImage p;
|
||||
if (p.loadFromData(archive.getRawDataAtIndex(index))) {
|
||||
_coverSize = QPair<int, int>(p.width(), p.height());
|
||||
QImage scaled;
|
||||
if (p.width() > p.height()) //landscape??
|
||||
{
|
||||
scaled = p.scaledToWidth(640, Qt::SmoothTransformation);
|
||||
} else {
|
||||
scaled = p.scaledToWidth(480, Qt::SmoothTransformation);
|
||||
}
|
||||
scaled.save(_target, 0, 75);
|
||||
} else {
|
||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||
//p.load(":/images/notCover.png");
|
||||
//p.save(_target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "properties_dialog.h"
|
||||
|
||||
#include "data_base_management.h"
|
||||
#include "library_creator.h"
|
||||
#include "initial_comic_info_extractor.h"
|
||||
#include "yacreader_field_edit.h"
|
||||
#include "yacreader_field_plain_text_edit.h"
|
||||
#include "db_helper.h"
|
||||
@ -22,6 +22,8 @@
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace YACReader;
|
||||
|
||||
PropertiesDialog::PropertiesDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
@ -734,12 +736,12 @@ void PropertiesDialog::save()
|
||||
if (comics.count() == 1) {
|
||||
if (coverChanged) // && coverPageEdit->text().toInt() != *comics[0].info.coverPage)
|
||||
{
|
||||
ThumbnailCreator tc(basePath + comics[0].path, basePath + "/.yacreaderlibrary/covers/" + comics[0].info.hash + ".jpg", comics[0].info.coverPage.toInt());
|
||||
tc.create();
|
||||
InitialComicInfoExtractor ie(basePath + comics[0].path, basePath + "/.yacreaderlibrary/covers/" + comics[0].info.hash + ".jpg", comics[0].info.coverPage.toInt());
|
||||
ie.extract();
|
||||
|
||||
if (tc.getOriginalCoverSize().second > 0) {
|
||||
comics[0].info.originalCoverSize = QString("%1x%2").arg(tc.getOriginalCoverSize().first).arg(tc.getOriginalCoverSize().second);
|
||||
comics[0].info.coverSizeRatio = static_cast<float>(tc.getOriginalCoverSize().first) / tc.getOriginalCoverSize().second;
|
||||
if (ie.getOriginalCoverSize().second > 0) {
|
||||
comics[0].info.originalCoverSize = QString("%1x%2").arg(ie.getOriginalCoverSize().first).arg(ie.getOriginalCoverSize().second);
|
||||
comics[0].info.coverSizeRatio = static_cast<float>(ie.getOriginalCoverSize().first) / ie.getOriginalCoverSize().second;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -831,9 +833,9 @@ void PropertiesDialog::loadNextCover()
|
||||
if (current < comics.at(0).info.numPages.toInt()) {
|
||||
updateCoverPageNumberLabel(current + 1);
|
||||
|
||||
ThumbnailCreator tc(basePath + comics[0].path, "", current + 1);
|
||||
tc.create();
|
||||
setCover(tc.getCover());
|
||||
InitialComicInfoExtractor ie(basePath + comics[0].path, "", current + 1);
|
||||
ie.extract();
|
||||
setCover(ie.getCover());
|
||||
repaint();
|
||||
|
||||
if ((current + 1) == comics.at(0).info.numPages.toInt()) {
|
||||
@ -854,9 +856,9 @@ void PropertiesDialog::loadPreviousCover()
|
||||
int current = coverPageNumberLabel->text().toInt();
|
||||
if (current != 1) {
|
||||
updateCoverPageNumberLabel(current - 1);
|
||||
ThumbnailCreator tc(basePath + comics[0].path, "", current - 1);
|
||||
tc.create();
|
||||
setCover(tc.getCover());
|
||||
InitialComicInfoExtractor ie(basePath + comics[0].path, "", current - 1);
|
||||
ie.extract();
|
||||
setCover(ie.getCover());
|
||||
repaint();
|
||||
|
||||
if ((current - 1) == 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user