Parse through all movies in movieDB response. Test with single response.
This commit is contained in:
parent
1147218e0c
commit
d339ced03b
3
main.cpp
3
main.cpp
@ -25,7 +25,8 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
QMovieDB movieDB(settings.value("MovieDB API Key").toString());
|
QMovieDB movieDB(settings.value("MovieDB API Key").toString());
|
||||||
|
|
||||||
movieDB.searchMovieTitle("The Shawshank Redemption");
|
//movieDB.searchMovieTitle("10 cloverfield lane"); //Single Result Example
|
||||||
|
movieDB.searchMovieTitle("The Shawshank Redemption"); //Multi-result
|
||||||
|
|
||||||
// //Check if HDR/DolbyVision
|
// //Check if HDR/DolbyVision
|
||||||
// enum QMediaInfo::HDR_Type hdrType = mInfo.getHDRType(__T("Cosmos.mkv"));
|
// enum QMediaInfo::HDR_Type hdrType = mInfo.getHDRType(__T("Cosmos.mkv"));
|
||||||
|
18
qmoviedb.cpp
18
qmoviedb.cpp
@ -32,24 +32,22 @@ void QMovieDB::receiveReply(QNetworkReply *reply) {
|
|||||||
if (responseStatus == 200) {
|
if (responseStatus == 200) {
|
||||||
parseResults(QJsonDocument::fromJson(reply->readAll()).object());
|
parseResults(QJsonDocument::fromJson(reply->readAll()).object());
|
||||||
} else {
|
} else {
|
||||||
qInfo() << "Invalid Response. Status: " << responseStatus;
|
qWarning() << "Invalid Response. Status: " << responseStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMovieDB::parseResults(QJsonObject json) {
|
void QMovieDB::parseResults(QJsonObject json) {
|
||||||
qInfo() << "Total Results: " << json.value("total_results").toInt();
|
qInfo() << "Total Results: " << json.value("total_results").toInt();
|
||||||
|
|
||||||
QJsonValue results = json.value("results");
|
QJsonArray results = json.value("results").toArray(); //Even if single result, always returns array of result(s).
|
||||||
QString releaseYear;
|
|
||||||
QString titleYear;
|
|
||||||
|
|
||||||
if (results.isArray()) {
|
for (int i = 0; i < results.size(); i++) {
|
||||||
releaseYear = results.toArray().first().toObject().value("release_date").toString();
|
QString releaseYear = results.at(i).toObject().value("release_date").toString();
|
||||||
releaseYear = "(" + releaseYear.left(releaseYear.indexOf("-")) + ")";
|
releaseYear = "(" + releaseYear.left(releaseYear.indexOf("-")) + ")";
|
||||||
titleYear = results.toArray().first().toObject().value("title").toString() + " " + releaseYear;
|
QString titleYear = results.at(i).toObject().value("title").toString() + " " + releaseYear;
|
||||||
} else {
|
|
||||||
//If single result
|
qInfo() << "Result " << (i + 1) << ": " << titleYear;
|
||||||
}
|
}
|
||||||
|
|
||||||
qInfo() << titleYear;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user