mirror of
https://github.com/YACReader/yacreader
synced 2025-07-22 06:54:39 -04: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";
|
||||
//gets comic detail
|
||||
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
|
||||
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
|
||||
void ComicVineClient::getComicDetail(const QString & id)
|
||||
QByteArray ComicVineClient::getComicDetail(const QString & 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(finished()),search,SLOT(deleteLater()));
|
||||
|
||||
//connect(search,SIGNAL(dataReady(const QByteArray &)),this,SLOT(proccessComicDetailData(const QByteArray &)));
|
||||
//connect(search,SIGNAL(timeout()),this,SIGNAL(timeOut()));
|
||||
//connect(search,SIGNAL(finished()),search,SLOT(deleteLater()));
|
||||
search->get();
|
||||
search->wait();
|
||||
QByteArray result = search->getResult();
|
||||
delete search;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ComicVineClient::getComicCover(const QString &url)
|
||||
|
@ -25,7 +25,7 @@ public slots:
|
||||
void getSeriesDetail(const QString & id);
|
||||
void getSeriesCover(const QString & url);
|
||||
void getVolumeComicsInfo(const QString & idVolume);
|
||||
void getComicDetail(const QString & id);
|
||||
QByteArray getComicDetail(const QString & id);
|
||||
void getComicCover(const QString & url);
|
||||
|
||||
void getComicId(const QString & id, int comicNumber);
|
||||
|
@ -7,6 +7,10 @@
|
||||
#include <QRadioButton>
|
||||
#include <QMessageBox>
|
||||
#include <QTableView>
|
||||
#include <QtConcurrent/QtConcurrentRun>
|
||||
#include <QSqlDatabase>
|
||||
#include <QtScript>
|
||||
#include "data_base_management.h"
|
||||
|
||||
#include "yacreader_busy_widget.h"
|
||||
#include "comic_vine_client.h"
|
||||
@ -18,10 +22,11 @@
|
||||
#include "select_comic.h"
|
||||
#include "select_volume.h"
|
||||
#include "sort_volume_comics.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "response_parser.h"
|
||||
|
||||
|
||||
|
||||
ComicVineDialog::ComicVineDialog(QWidget *parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
@ -141,6 +146,12 @@ void ComicVineDialog::goNext()
|
||||
connect(comicVineClient,SIGNAL(timeOut()),this,SLOT(queryTimeOut()));
|
||||
connect(comicVineClient,SIGNAL(finished()),comicVineClient,SLOT(deleteLater()));
|
||||
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()
|
||||
{
|
||||
content->setCurrentIndex(0);
|
||||
|
@ -29,10 +29,13 @@ public:
|
||||
QString databasePath;
|
||||
QString basePath;
|
||||
void setComics(const QList<ComicDB> & comics);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void show();
|
||||
|
||||
protected slots:
|
||||
void goNext();
|
||||
void goBack();
|
||||
@ -51,6 +54,9 @@ protected slots:
|
||||
void showSelectComic(const QString & json);
|
||||
void showSortVolumeComics(const QString & json);
|
||||
void queryTimeOut();
|
||||
void getComicsInfo(QList<QPair<ComicDB,QString> > & matchingInfo);
|
||||
ComicDB parseComicInfo(ComicDB &comic, const QString & json);
|
||||
|
||||
private:
|
||||
|
||||
enum ScraperMode
|
||||
|
@ -86,6 +86,11 @@ QModelIndex LocalComicListModel::index(int row, int column, const QModelIndex &p
|
||||
return createIndex(row, column);
|
||||
}
|
||||
|
||||
QList<ComicDB> LocalComicListModel::getData()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
void LocalComicListModel::moveSelectionUp(const QList<QModelIndex> &selectedIndexes)
|
||||
{
|
||||
QModelIndex mi = selectedIndexes.first();
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
QList<ComicDB> getData();
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
@ -149,7 +149,17 @@ QModelIndex VolumeComicsModel::index(int row, int column, const QModelIndex &par
|
||||
|
||||
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
|
||||
|
@ -22,6 +22,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
QString getComicId(const QModelIndex &index) const;
|
||||
QString getComicId(int row) const;
|
||||
QString getCoverURL(const QModelIndex &index) const;
|
||||
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:
|
||||
void setData(QList<ComicDB> & comics, const QString & json);
|
||||
QList<QPair<ComicDB,QString> > getMatchingInfo();
|
||||
|
||||
protected slots:
|
||||
void synchronizeScroll(int pos);
|
||||
@ -75,6 +76,7 @@ protected slots:
|
||||
void moveUpIL();
|
||||
void moveDownIL();
|
||||
|
||||
|
||||
private:
|
||||
ScraperTableView * tableFiles;
|
||||
ScraperTableView * tableVolumeComics;
|
||||
|
@ -706,6 +706,9 @@ void LibraryWindow::createConnections()
|
||||
//properties & config
|
||||
connect(propertiesDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
|
||||
|
||||
//comic vine
|
||||
connect(comicVineDialog,SIGNAL(accepted()),this,SLOT(reloadCovers()));
|
||||
|
||||
connect(updateLibraryAction,SIGNAL(triggered()),this,SLOT(updateLibrary()));
|
||||
connect(renameLibraryAction,SIGNAL(triggered()),this,SLOT(renameLibrary()));
|
||||
//connect(deleteLibraryAction,SIGNAL(triggered()),this,SLOT(deleteLibrary()));
|
||||
|
Reference in New Issue
Block a user