thetvdb v2
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "ui_cmainwindow.h"
|
||||
|
||||
#include "cthetvdb.h"
|
||||
#include "cthetvdbv2.h"
|
||||
#include "cseasondelegate.h"
|
||||
#include "csearch.h"
|
||||
#include "cmessageanimatedialog.h"
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "ui_csearch.h"
|
||||
|
||||
#include "cthetvdb.h"
|
||||
#include "cthetvdbv2.h"
|
||||
|
||||
#include "cserie.h"
|
||||
#include "cmessageanimatedialog.h"
|
||||
|
||||
@@ -38,7 +40,9 @@ void cSearch::on_m_lpSearchButton_clicked()
|
||||
lpDialog->show();
|
||||
|
||||
cTheTVDB theTVDB;
|
||||
cTheTVDBV2 theTVDBV2;
|
||||
QList<cSerie*> serieList = theTVDB.search(ui->m_lpSearch->text());
|
||||
QList<cSerie*> serieList2 = theTVDBV2.search(ui->m_lpSearch->text());
|
||||
|
||||
ui->m_lpResults->clear();
|
||||
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
#include "cthetvdbv2.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QEventLoop>
|
||||
#include <QByteArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
|
||||
cTheTVDBV2::cTheTVDBV2()
|
||||
{
|
||||
QByteArray jsonRequest = "{\"apikey\":\"BC0893B659680049\"}";
|
||||
QByteArray postDataSize = QByteArray::number(jsonRequest.size());
|
||||
QNetworkAccessManager networkManager;
|
||||
|
||||
QNetworkRequest request(QUrl(QString("https://api.thetvdb.com/login")));
|
||||
|
||||
request.setRawHeader("Content-Type", "application/json");
|
||||
request.setRawHeader("Content-Length", postDataSize);
|
||||
|
||||
QNetworkReply* reply = networkManager.post(request, jsonRequest);
|
||||
QEventLoop loop;
|
||||
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QString strReply = (QString)reply->readAll();
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
|
||||
QJsonObject jsonObj = jsonResponse.object();
|
||||
m_szToken = jsonObj["token"].toString();
|
||||
|
||||
delete reply;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << reply->errorString();
|
||||
delete reply;
|
||||
}
|
||||
}
|
||||
|
||||
QList<cSerie*> cTheTVDBV2::search(const QString& szSerie, const QString& szLanguage)
|
||||
{
|
||||
QList<cSerie*> serieList;
|
||||
|
||||
QNetworkAccessManager networkManager;
|
||||
|
||||
QNetworkRequest request(QUrl(QString("https://api.thetvdb.com/search/series?name=%1").arg(szSerie)));
|
||||
|
||||
request.setRawHeader("Content-Type", "application/json");
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_szToken).toUtf8());
|
||||
if(!szLanguage.contains("all"))
|
||||
request.setRawHeader("Accept-Language", szLanguage.toUtf8());
|
||||
|
||||
QNetworkReply* reply = networkManager.get(request);
|
||||
QEventLoop loop;
|
||||
|
||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
loop.exec();
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QString strReply = (QString)reply->readAll();
|
||||
QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
|
||||
QJsonObject jsonObj = jsonResponse.object();
|
||||
QJsonArray jsonArray = jsonObj["data"].toArray();
|
||||
|
||||
for(int z = 0;z < jsonArray.count();z++)
|
||||
{
|
||||
QJsonObject serie = jsonArray[z].toObject();
|
||||
cSerie* lpSerie = new cSerie;
|
||||
lpSerie->setID(serie["id"].toInt());
|
||||
lpSerie->setSeriesName(serie["seriesName"].toString());
|
||||
lpSerie->setFirstAired(serie["firstAired"].toString());
|
||||
serieList.append(lpSerie);
|
||||
}
|
||||
delete reply;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << reply->errorString();
|
||||
delete reply;
|
||||
}
|
||||
return(serieList);
|
||||
}
|
||||
|
||||
/*
|
||||
cSerie* cTheTVDBV2::parseSeries(const QDomElement& element)
|
||||
{
|
||||
}
|
||||
*/
|
||||
/*
|
||||
cSerie* cTheTVDBV2::load(const qint32 &iID, const QString &szLanguage)
|
||||
{
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef CTHETVDBV2_H
|
||||
#define CTHETVDBV2_H
|
||||
|
||||
|
||||
#include "cserie.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
class cTheTVDBV2
|
||||
{
|
||||
public:
|
||||
cTheTVDBV2();
|
||||
|
||||
QList<cSerie*> search(const QString& szSerie, const QString& szLanguage = "all");
|
||||
// cSerie* load(const qint32 &iID, const QString& szLanguage);
|
||||
private:
|
||||
QString m_szToken;
|
||||
// cSerie* parseSeries(const QDomElement& element);
|
||||
// void parseEpisode(cSerie* lpSerie, const QDomElement& element);
|
||||
};
|
||||
|
||||
#endif // CTHETVDBV2_H
|
||||
+4
-2
@@ -28,7 +28,8 @@ SOURCES += main.cpp\
|
||||
cepisodedetails.cpp \
|
||||
cmessagedialog.cpp \
|
||||
cupdatethread.cpp \
|
||||
cpicturesthread.cpp
|
||||
cpicturesthread.cpp \
|
||||
cthetvdbv2.cpp
|
||||
|
||||
HEADERS += cmainwindow.h \
|
||||
cthetvdb.h \
|
||||
@@ -45,7 +46,8 @@ HEADERS += cmainwindow.h \
|
||||
cepisodedetails.h \
|
||||
cmessagedialog.h \
|
||||
cupdatethread.h \
|
||||
cpicturesthread.h
|
||||
cpicturesthread.h \
|
||||
cthetvdbv2.h
|
||||
|
||||
FORMS += cmainwindow.ui \
|
||||
csearch.ui \
|
||||
|
||||
Reference in New Issue
Block a user