mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
getting most of the info from comic vine
This commit is contained in:
parent
9c4ecd72af
commit
bbb74b64b9
@ -151,7 +151,9 @@ void ComicVineDialog::goNext()
|
||||
|
||||
//ComicDB-ComicVineID
|
||||
QList<QPair<ComicDB,QString> > matchingInfo = sortVolumeComicsWidget->getMatchingInfo();
|
||||
QtConcurrent::run(this, &ComicVineDialog::getComicsInfo,matchingInfo);
|
||||
int count = selectVolumeWidget->getSelectedVolumeNumIssues();
|
||||
QString publisher = selectVolumeWidget->getSelectedVolumePublisher();
|
||||
QtConcurrent::run(this, &ComicVineDialog::getComicsInfo,matchingInfo,count,publisher);
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +357,7 @@ void ComicVineDialog::queryTimeOut()
|
||||
}
|
||||
}
|
||||
|
||||
void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString> > & matchingInfo)
|
||||
void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString> > & matchingInfo, int count,const QString & publisher)
|
||||
{
|
||||
QPair<ComicDB, QString> p;
|
||||
QList<ComicDB> comics;
|
||||
@ -366,7 +368,7 @@ void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString> > & matchingIn
|
||||
//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
|
||||
comics.push_back(parseComicInfo(p.first,result,count,publisher)); //TODO check result error
|
||||
}
|
||||
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(databasePath);
|
||||
@ -384,7 +386,7 @@ void ComicVineDialog::getComicsInfo(QList<QPair<ComicDB, QString> > & matchingIn
|
||||
emit accepted();
|
||||
}
|
||||
|
||||
ComicDB ComicVineDialog::parseComicInfo(ComicDB & comic, const QString & json)
|
||||
ComicDB ComicVineDialog::parseComicInfo(ComicDB & comic, const QString & json, int count, const QString & publisher)
|
||||
{
|
||||
QScriptEngine engine;
|
||||
QScriptValue sc;
|
||||
@ -405,44 +407,112 @@ ComicDB ComicVineDialog::parseComicInfo(ComicDB & comic, const QString & json)
|
||||
QString title = result.property("name").toString();
|
||||
|
||||
QString number = result.property("issue_number").toString();
|
||||
QString count; //get from select volume
|
||||
//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 arcCount; //count_of_issue_appearances -> NO
|
||||
|
||||
QString genere; //no
|
||||
|
||||
QString writer;
|
||||
QString penciller;
|
||||
QString inker;
|
||||
QString colorist;
|
||||
QString letterer;
|
||||
QString coverArtist;
|
||||
QMap<QString,QString> authors = getAuthors(result.property("person_credits"));
|
||||
|
||||
QString writer = QStringList(authors.values("writer")).join("\n");
|
||||
QString penciller = QStringList(authors.values("penciller")).join("\n");
|
||||
QString inker = QStringList(authors.values("inker")).join("\n");
|
||||
QString colorist = QStringList(authors.values("colorist")).join("\n");
|
||||
QString letterer = QStringList(authors.values("letterer")).join("\n");
|
||||
QString coverArtist = QStringList(authors.values("cover")).join("\n");
|
||||
|
||||
QString date = result.property("cover_date").toString();
|
||||
|
||||
QString publisher; //get from select volume
|
||||
//QString publisher; //get from select volume
|
||||
QString format; //no
|
||||
bool color; //no
|
||||
QString ageRating; //no
|
||||
|
||||
QString synopsis = result.property("description").toString(); //description
|
||||
QString characters;
|
||||
QString synopsis = result.property("description").toString().remove(QRegExp("<[^>]*>")); //description
|
||||
QString characters = getCharacters(result.property("character_credits"));
|
||||
|
||||
comic.info.setTitle(title);
|
||||
|
||||
comic.info.setNumber(number.toInt());
|
||||
comic.info.setCount(count);
|
||||
|
||||
comic.info.setWriter(writer);
|
||||
comic.info.setPenciller(penciller);
|
||||
comic.info.setInker(inker);
|
||||
comic.info.setColorist(colorist);
|
||||
comic.info.setLetterer(letterer);
|
||||
comic.info.setCoverArtist(coverArtist);
|
||||
|
||||
QStringList tempList = date.split("-");
|
||||
std::reverse(tempList.begin(),tempList.end());
|
||||
comic.info.setDate(tempList.join("/"));
|
||||
comic.info.setVolume(volume);
|
||||
|
||||
comic.info.setPublisher(publisher);
|
||||
|
||||
comic.info.setSynopsis(synopsis);
|
||||
comic.info.setCharacters(characters);
|
||||
}
|
||||
}
|
||||
return comic;
|
||||
return comic;
|
||||
}
|
||||
|
||||
QString ComicVineDialog::getCharacters(const QScriptValue &json_characters)
|
||||
{
|
||||
QString characters;
|
||||
|
||||
QScriptValueIterator it(json_characters);
|
||||
QScriptValue resultsValue;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if(it.flags() & QScriptValue::SkipInEnumeration)
|
||||
continue;
|
||||
resultsValue = it.value();
|
||||
|
||||
characters += resultsValue.property("name").toString() + "\n";
|
||||
}
|
||||
|
||||
return characters;
|
||||
}
|
||||
|
||||
QMap<QString, QString> ComicVineDialog::getAuthors(const QScriptValue &json_authors)
|
||||
{
|
||||
QMap<QString, QString> authors;
|
||||
|
||||
QScriptValueIterator it(json_authors);
|
||||
QScriptValue resultsValue;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if(it.flags() & QScriptValue::SkipInEnumeration)
|
||||
continue;
|
||||
resultsValue = it.value();
|
||||
|
||||
QString authorName = resultsValue.property("name").toString();
|
||||
|
||||
QStringList roles = resultsValue.property("role").toString().split(",");
|
||||
foreach(QString role, roles)
|
||||
{
|
||||
if(role.trimmed() == "writer")
|
||||
authors.insertMulti("writer",authorName);
|
||||
else if(role.trimmed() == "inker")
|
||||
authors.insertMulti("inker",authorName);
|
||||
else if(role.trimmed() == "penciler" || role.trimmed() == "penciller")
|
||||
authors.insertMulti("penciller",authorName);
|
||||
else if(role.trimmed() == "colorist")
|
||||
authors.insertMulti("colorist",authorName);
|
||||
else if(role.trimmed() == "letterer")
|
||||
authors.insertMulti("letterer",authorName);
|
||||
else if(role.trimmed() == "cover")
|
||||
authors.insertMulti("cover",authorName);
|
||||
}
|
||||
}
|
||||
|
||||
return authors;
|
||||
}
|
||||
|
||||
void ComicVineDialog::showLoading()
|
||||
|
@ -18,6 +18,7 @@ class SearchVolume;
|
||||
class SelectComic;
|
||||
class SelectVolume;
|
||||
class SortVolumeComics;
|
||||
class QScriptValue;
|
||||
|
||||
//TODO this should use a QStateMachine
|
||||
//----------------------------------------
|
||||
@ -54,11 +55,14 @@ 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);
|
||||
void getComicsInfo(QList<QPair<ComicDB,QString> > & matchingInfo, int count, const QString & publisher);
|
||||
ComicDB parseComicInfo(ComicDB &comic, const QString & json, int count, const QString &publisher);
|
||||
|
||||
private:
|
||||
|
||||
QString getCharacters(const QScriptValue & json_characters);
|
||||
QMap<QString,QString> getAuthors(const QScriptValue & json_authors);
|
||||
|
||||
enum ScraperMode
|
||||
{
|
||||
SingleComic, //the scraper has been opened for a single comic
|
||||
|
@ -29,12 +29,13 @@ void VolumeComicsModel::load(const QString & json)
|
||||
}
|
||||
else
|
||||
{
|
||||
int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext
|
||||
QScriptValueIterator it(sc.property("results"));
|
||||
//bool test;
|
||||
QScriptValue resultsValue;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if(it.flags() & QScriptValue::SkipInEnumeration)
|
||||
continue;
|
||||
resultsValue = it.value();
|
||||
QString issueNumber = resultsValue.property("issue_number").toString();
|
||||
QString name = resultsValue.property("name").toString();
|
||||
@ -42,10 +43,7 @@ void VolumeComicsModel::load(const QString & json)
|
||||
QString id = resultsValue.property("id").toString();
|
||||
QStringList l;
|
||||
l << issueNumber << name << coverURL << id;
|
||||
//test = name.isEmpty() && year.isEmpty() && numIssues.isEmpty() && url.isEmpty();
|
||||
if(numResults > 0)
|
||||
_data.push_back(l);
|
||||
numResults--;
|
||||
_data.push_back(l);
|
||||
}
|
||||
|
||||
qSort(_data.begin(),_data.end(),lessThan);
|
||||
|
@ -141,7 +141,17 @@ QModelIndex VolumesModel::index(int row, int column, const QModelIndex &parent)
|
||||
|
||||
QString VolumesModel::getVolumeId(const QModelIndex &index) const
|
||||
{
|
||||
return _data[index.row()][ID];
|
||||
return _data[index.row()][ID];
|
||||
}
|
||||
|
||||
int VolumesModel::getNumIssues(const QModelIndex &index) const
|
||||
{
|
||||
return _data[index.row()][ISSUES].toInt();
|
||||
}
|
||||
|
||||
QString VolumesModel::getPublisher(const QModelIndex &index) const
|
||||
{
|
||||
return _data[index.row()][PUBLISHER];
|
||||
}
|
||||
|
||||
QString VolumesModel::getCoverURL(const QModelIndex &index) const
|
||||
|
@ -23,6 +23,8 @@ public:
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
QString getVolumeId(const QModelIndex & index) const;
|
||||
int getNumIssues(const QModelIndex & index) const;
|
||||
QString getPublisher(const QModelIndex & index) const;
|
||||
QString getCoverURL(const QModelIndex & index) const;
|
||||
|
||||
signals:
|
||||
|
@ -146,6 +146,16 @@ void SelectVolume::setDescription(const QString & jsonDetail)
|
||||
|
||||
QString SelectVolume::getSelectedVolumeId()
|
||||
{
|
||||
return model->getVolumeId(tableVolumes->currentIndex());
|
||||
return model->getVolumeId(tableVolumes->currentIndex());
|
||||
}
|
||||
|
||||
int SelectVolume::getSelectedVolumeNumIssues()
|
||||
{
|
||||
return model->getNumIssues(tableVolumes->currentIndex());
|
||||
}
|
||||
|
||||
QString SelectVolume::getSelectedVolumePublisher()
|
||||
{
|
||||
return model->getPublisher(tableVolumes->currentIndex());
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@ public slots:
|
||||
void setCover(const QByteArray &);
|
||||
void setDescription(const QString & jsonDetail);
|
||||
QString getSelectedVolumeId();
|
||||
int getSelectedVolumeNumIssues();
|
||||
QString getSelectedVolumePublisher();
|
||||
|
||||
private:
|
||||
QLabel * cover;
|
||||
|
Loading…
x
Reference in New Issue
Block a user