mirror of
https://github.com/YACReader/yacreader
synced 2026-02-12 10:10:31 -05:00
first version saving some info from comic vine
This commit is contained in:
@ -27,6 +27,7 @@ static const QString CV_COMIC_ID = CV_WEB_ADDRESS + "/issues/?api_key=" + CV_API
|
|||||||
"&filter=volume:%1,issue_number:%2";
|
"&filter=volume:%1,issue_number:%2";
|
||||||
//gets comic detail
|
//gets comic detail
|
||||||
static const QString CV_COMIC_DETAIL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json";
|
static const QString CV_COMIC_DETAIL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json";
|
||||||
|
//http://www.comicvine.com/api/issue/4000-%1/?api_key=46680bebb358f1de690a5a365e15d325f9649f91&format=json
|
||||||
|
|
||||||
//gets comic cover URL
|
//gets comic cover URL
|
||||||
static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json&field_list=image";
|
static const QString CV_COVER_URL = CV_WEB_ADDRESS + "/issue/4000-%1/?api_key=" + CV_API_KEY + "&format=json&field_list=image";
|
||||||
@ -114,13 +115,19 @@ void ComicVineClient::getComicId(const QString & id, int comicNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//CV_COMIC_DETAIL
|
//CV_COMIC_DETAIL
|
||||||
void ComicVineClient::getComicDetail(const QString & id)
|
QByteArray ComicVineClient::getComicDetail(const QString & id)
|
||||||
{
|
{
|
||||||
HttpWorker * search = new HttpWorker(CV_COMIC_DETAIL.arg(id));
|
HttpWorker * search = new HttpWorker(CV_COMIC_DETAIL.arg(id));
|
||||||
connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &)));
|
|
||||||
connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
//connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &)));
|
||||||
connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
//connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
||||||
|
//connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||||
search->get();
|
search->get();
|
||||||
|
search->wait();
|
||||||
|
QByteArray result = search->getResult();
|
||||||
|
delete search;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComicVineClient::getComicCover(const QString &url)
|
void ComicVineClient::getComicCover(const QString &url)
|
||||||
|
|||||||
@ -25,7 +25,7 @@ public slots:
|
|||||||
void getSeriesDetail(const QString & id);
|
void getSeriesDetail(const QString & id);
|
||||||
void getSeriesCover(const QString & url);
|
void getSeriesCover(const QString & url);
|
||||||
void getVolumeComicsInfo(const QString & idVolume);
|
void getVolumeComicsInfo(const QString & idVolume);
|
||||||
void getComicDetail(const QString & id);
|
QByteArray getComicDetail(const QString & id);
|
||||||
void getComicCover(const QString & url);
|
void getComicCover(const QString & url);
|
||||||
|
|
||||||
void getComicId(const QString & id, int comicNumber);
|
void getComicId(const QString & id, int comicNumber);
|
||||||
|
|||||||
@ -7,6 +7,10 @@
|
|||||||
#include <QRadioButton>
|
#include <QRadioButton>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
#include <QtConcurrent/QtConcurrentRun>
|
||||||
|
#include <QSqlDatabase>
|
||||||
|
#include <QtScript>
|
||||||
|
#include "data_base_management.h"
|
||||||
|
|
||||||
#include "yacreader_busy_widget.h"
|
#include "yacreader_busy_widget.h"
|
||||||
#include "comic_vine_client.h"
|
#include "comic_vine_client.h"
|
||||||
@ -18,10 +22,11 @@
|
|||||||
#include "select_comic.h"
|
#include "select_comic.h"
|
||||||
#include "select_volume.h"
|
#include "select_volume.h"
|
||||||
#include "sort_volume_comics.h"
|
#include "sort_volume_comics.h"
|
||||||
|
#include "db_helper.h"
|
||||||
#include "response_parser.h"
|
#include "response_parser.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ComicVineDialog::ComicVineDialog(QWidget *parent) :
|
ComicVineDialog::ComicVineDialog(QWidget *parent) :
|
||||||
QDialog(parent)
|
QDialog(parent)
|
||||||
{
|
{
|
||||||
@ -141,6 +146,12 @@ void ComicVineDialog::goNext()
|
|||||||
connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut()));
|
connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut()));
|
||||||
connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater()));
|
connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater()));
|
||||||
comicVineClient->getVolumeComicsInfo(selectVolumeWidget->getSelectedVolumeId());
|
comicVineClient->getVolumeComicsInfo(selectVolumeWidget->getSelectedVolumeId());
|
||||||
|
} else if (content->currentWidget() == sortVolumeComicsWidget) {
|
||||||
|
showLoading();
|
||||||
|
|
||||||
|
//ComicDB-ComicVineID
|
||||||
|
QList<QPair<ComicDB,QString> > matchingInfo = sortVolumeComicsWidget->getMatchingInfo();
|
||||||
|
QtConcurrent::run(this, &ComicVineDialog::getComicsInfo,matchingInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,6 +355,96 @@ void ComicVineDialog::queryTimeOut()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString> > & matchingInfo)
|
||||||
|
{
|
||||||
|
QPair<ComicDB, QString> p;
|
||||||
|
QList<ComicDB> comics;
|
||||||
|
foreach (p, matchingInfo) {
|
||||||
|
ComicVineClient * comicVineClient = new ComicVineClient;
|
||||||
|
//connect(comicVineClient,SIGNAL(searchResult(QString)),this,SLOT(debugClientResults(QString)));
|
||||||
|
//connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut()));
|
||||||
|
//connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater()));
|
||||||
|
QByteArray result = comicVineClient->getComicDetail(p.second); //TODO check timeOut or Connection error
|
||||||
|
|
||||||
|
comics.push_back(parseComicInfo(p.first,result)); //TODO check result error
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||||
|
db.open();
|
||||||
|
db.transaction();
|
||||||
|
foreach(ComicDB comic, comics)
|
||||||
|
{
|
||||||
|
DBHelper::update(&(comic.info),db);
|
||||||
|
}
|
||||||
|
db.commit();
|
||||||
|
db.close();
|
||||||
|
QSqlDatabase::removeDatabase(databasePath);
|
||||||
|
|
||||||
|
close();
|
||||||
|
emit accepted();
|
||||||
|
}
|
||||||
|
|
||||||
|
ComicDB ComicVineDialog::parseComicInfo(ComicDB & comic, const QString & json)
|
||||||
|
{
|
||||||
|
QScriptEngine engine;
|
||||||
|
QScriptValue sc;
|
||||||
|
sc = engine.evaluate("(" + json + ")");
|
||||||
|
|
||||||
|
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
||||||
|
{
|
||||||
|
qDebug("Error detected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext
|
||||||
|
|
||||||
|
if(numResults > 0)
|
||||||
|
{
|
||||||
|
QScriptValue result = sc.property("results");
|
||||||
|
|
||||||
|
QString title = result.property("name").toString();
|
||||||
|
|
||||||
|
QString number = result.property("issue_number").toString();
|
||||||
|
QString count; //get from select volume
|
||||||
|
|
||||||
|
|
||||||
|
QString volume = result.property("volume").property("name").toString();
|
||||||
|
QString storyArc; //story_arc
|
||||||
|
QString arcNumber; //??
|
||||||
|
QString arcCount; //count_of_issue_appearances
|
||||||
|
|
||||||
|
QString genere; //no
|
||||||
|
|
||||||
|
QString writer;
|
||||||
|
QString penciller;
|
||||||
|
QString inker;
|
||||||
|
QString colorist;
|
||||||
|
QString letterer;
|
||||||
|
QString coverArtist;
|
||||||
|
|
||||||
|
QString date = result.property("cover_date").toString();
|
||||||
|
|
||||||
|
QString publisher; //get from select volume
|
||||||
|
QString format; //no
|
||||||
|
bool color; //no
|
||||||
|
QString ageRating; //no
|
||||||
|
|
||||||
|
QString synopsis = result.property("description").toString(); //description
|
||||||
|
QString characters;
|
||||||
|
|
||||||
|
comic.info.setTitle(title);
|
||||||
|
|
||||||
|
comic.info.setNumber(number.toInt());
|
||||||
|
|
||||||
|
QStringList tempList = date.split("-");
|
||||||
|
std::reverse(tempList.begin(),tempList.end());
|
||||||
|
comic.info.setDate(tempList.join("/"));
|
||||||
|
comic.info.setVolume(volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comic;
|
||||||
|
}
|
||||||
|
|
||||||
void ComicVineDialog::showLoading()
|
void ComicVineDialog::showLoading()
|
||||||
{
|
{
|
||||||
content->setCurrentIndex(0);
|
content->setCurrentIndex(0);
|
||||||
|
|||||||
@ -29,10 +29,13 @@ public:
|
|||||||
QString databasePath;
|
QString databasePath;
|
||||||
QString basePath;
|
QString basePath;
|
||||||
void setComics(const QList<ComicDB> & comics);
|
void setComics(const QList<ComicDB> & comics);
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void goNext();
|
void goNext();
|
||||||
void goBack();
|
void goBack();
|
||||||
@ -51,6 +54,9 @@ protected slots:
|
|||||||
void showSelectComic(const QString & json);
|
void showSelectComic(const QString & json);
|
||||||
void showSortVolumeComics(const QString & json);
|
void showSortVolumeComics(const QString & json);
|
||||||
void queryTimeOut();
|
void queryTimeOut();
|
||||||
|
void getComicsInfo(QList<QPair<ComicDB,QString> > & matchingInfo);
|
||||||
|
ComicDB parseComicInfo(ComicDB &comic, const QString & json);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum ScraperMode
|
enum ScraperMode
|
||||||
|
|||||||
@ -86,6 +86,11 @@ QModelIndex LocalComicListModel::index(int row, int column, const QModelIndex &p
|
|||||||
return createIndex(row, column);
|
return createIndex(row, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ComicDB> LocalComicListModel::getData()
|
||||||
|
{
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
|
||||||
void LocalComicListModel::moveSelectionUp(const QList<QModelIndex> &selectedIndexes)
|
void LocalComicListModel::moveSelectionUp(const QList<QModelIndex> &selectedIndexes)
|
||||||
{
|
{
|
||||||
QModelIndex mi = selectedIndexes.first();
|
QModelIndex mi = selectedIndexes.first();
|
||||||
|
|||||||
@ -22,7 +22,7 @@ public:
|
|||||||
QVariant headerData(int section, Qt::Orientation orientation,
|
QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const;
|
int role = Qt::DisplayRole) const;
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
QList<ComicDB> getData();
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
@ -149,7 +149,17 @@ QModelIndex VolumeComicsModel::index(int row, int column, const QModelIndex &par
|
|||||||
|
|
||||||
QString VolumeComicsModel::getComicId(const QModelIndex &index) const
|
QString VolumeComicsModel::getComicId(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return _data[index.row()][ID];
|
int row = index.row();
|
||||||
|
if(row >= _data.count())
|
||||||
|
return "";
|
||||||
|
return _data[row][ID];
|
||||||
|
}
|
||||||
|
|
||||||
|
QString VolumeComicsModel::getComicId(int row) const
|
||||||
|
{
|
||||||
|
if(row >= _data.count())
|
||||||
|
return "";
|
||||||
|
return _data[row][ID];
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VolumeComicsModel::getCoverURL(const QModelIndex &index) const
|
QString VolumeComicsModel::getCoverURL(const QModelIndex &index) const
|
||||||
|
|||||||
@ -22,6 +22,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QString getComicId(const QModelIndex &index) const;
|
QString getComicId(const QModelIndex &index) const;
|
||||||
|
QString getComicId(int row) const;
|
||||||
QString getCoverURL(const QModelIndex &index) const;
|
QString getCoverURL(const QModelIndex &index) const;
|
||||||
void addExtraRows(int numRows);
|
void addExtraRows(int numRows);
|
||||||
|
|
||||||
|
|||||||
@ -162,3 +162,24 @@ void SortVolumeComics::moveDownIL()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QPair<ComicDB, QString> > SortVolumeComics::getMatchingInfo()
|
||||||
|
{
|
||||||
|
QList<ComicDB> comicList = localComicsModel->getData();
|
||||||
|
QList<QPair<ComicDB, QString> > l;
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
QString id;
|
||||||
|
foreach(ComicDB c, comicList)
|
||||||
|
{
|
||||||
|
id = volumeComicsModel->getComicId(index);
|
||||||
|
if(!c.getFileName().isEmpty() && !id.isEmpty()) //there is a valid comic, and valid comic ID
|
||||||
|
{
|
||||||
|
l.push_back(QPair<ComicDB, QString>(c,id));
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|||||||
@ -67,6 +67,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setData(QList<ComicDB> & comics, const QString & json);
|
void setData(QList<ComicDB> & comics, const QString & json);
|
||||||
|
QList<QPair<ComicDB,QString> > getMatchingInfo();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void synchronizeScroll(int pos);
|
void synchronizeScroll(int pos);
|
||||||
@ -75,6 +76,7 @@ protected slots:
|
|||||||
void moveUpIL();
|
void moveUpIL();
|
||||||
void moveDownIL();
|
void moveDownIL();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScraperTableView * tableFiles;
|
ScraperTableView * tableFiles;
|
||||||
ScraperTableView * tableVolumeComics;
|
ScraperTableView * tableVolumeComics;
|
||||||
|
|||||||
@ -706,6 +706,9 @@ void LibraryWindow::createConnections()
|
|||||||
//properties & config
|
//properties & config
|
||||||
connect(propertiesDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
|
connect(propertiesDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
|
||||||
|
|
||||||
|
//comic vine
|
||||||
|
connect(comicVineDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
|
||||||
|
|
||||||
connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary()));
|
connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary()));
|
||||||
connect(renameLibraryAction,SIGNAL(triggered()),this,SLOT(renameLibrary()));
|
connect(renameLibraryAction,SIGNAL(triggered()),this,SLOT(renameLibrary()));
|
||||||
//connect(deleteLibraryAction,SIGNAL(triggered()),this,SLOT(deleteLibrary()));
|
//connect(deleteLibraryAction,SIGNAL(triggered()),this,SLOT(deleteLibrary()));
|
||||||
|
|||||||
@ -23,6 +23,11 @@ void HttpWorker::get()
|
|||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray HttpWorker::getResult()
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void HttpWorker::run()
|
void HttpWorker::run()
|
||||||
{
|
{
|
||||||
QNetworkAccessManager manager;
|
QNetworkAccessManager manager;
|
||||||
@ -39,9 +44,10 @@ void HttpWorker::run()
|
|||||||
|
|
||||||
if(tT.isActive()){
|
if(tT.isActive()){
|
||||||
// download complete
|
// download complete
|
||||||
emit dataReady(reply->readAll());
|
result = reply->readAll();
|
||||||
|
emit dataReady(result);
|
||||||
tT.stop();
|
tT.stop();
|
||||||
} else {
|
} else {
|
||||||
emit timeout();
|
emit timeout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,11 +14,12 @@
|
|||||||
HttpWorker(const QString & urlString);
|
HttpWorker(const QString & urlString);
|
||||||
public slots:
|
public slots:
|
||||||
void get();
|
void get();
|
||||||
|
QByteArray getResult();
|
||||||
private:
|
private:
|
||||||
void run();
|
void run();
|
||||||
QUrl url;
|
QUrl url;
|
||||||
int httpGetId;
|
int httpGetId;
|
||||||
QByteArray content;
|
QByteArray result;
|
||||||
signals:
|
signals:
|
||||||
void dataReady(const QByteArray &);
|
void dataReady(const QByteArray &);
|
||||||
void timeout();
|
void timeout();
|
||||||
|
|||||||
Reference in New Issue
Block a user