Parse through all movies in movieDB response. Test with single response.

This commit is contained in:
Adam Bissen 2024-01-07 19:05:30 +00:00
parent 1147218e0c
commit d339ced03b
2 changed files with 10 additions and 11 deletions

View File

@ -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"));

View File

@ -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;
} }