added serie discover
This commit is contained in:
+141
-2
@@ -1,15 +1,154 @@
|
||||
#include "cdiscover.h"
|
||||
#include "ui_cdiscover.h"
|
||||
|
||||
#include "ccheckboxitemdelegate.h"
|
||||
#include "cthemoviedbv3.h"
|
||||
|
||||
cDiscover::cDiscover(QWidget *parent) :
|
||||
#include <QStandardItem>
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
cDiscover::cDiscover(const cSerieList serieList, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::cDiscover)
|
||||
ui(new Ui::cDiscover),
|
||||
m_serieList(serieList)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_lpGenresModel = new QStandardItemModel(0, 1);
|
||||
QStringList headerLabels = QStringList() << tr("Name");
|
||||
m_lpGenresModel->setHorizontalHeaderLabels(headerLabels);
|
||||
ui->m_lpGenres->setModel(m_lpGenresModel);
|
||||
ui->m_lpGenres->setItemDelegate(new cCheckBoxItemDelegate());
|
||||
ui->m_lpGenres->setWrapping(true);
|
||||
|
||||
m_lpSeriesModel = new QStandardItemModel(0, 1);
|
||||
ui->m_lpSeries->setModel(m_lpSeriesModel);
|
||||
|
||||
headerLabels = QStringList() << tr("Title") << tr("Year");
|
||||
m_lpSeriesModel->setHorizontalHeaderLabels(headerLabels);
|
||||
|
||||
connect(ui->m_lpVoting, &QxtSpanSlider::spanChanged, this, &cDiscover::spanChanged);
|
||||
|
||||
ui->m_lpVoting->setRange(0, 100);
|
||||
ui->m_lpVoting->setLowerValue(0);
|
||||
ui->m_lpVoting->setUpperValue(100);
|
||||
|
||||
cTheMovieDBV3 movieDB3;
|
||||
QMap<qint32, QString> genres;
|
||||
|
||||
genres = movieDB3.genresSerie("de-DE");
|
||||
|
||||
QMapIterator<qint32, QString> iterator(genres);
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
iterator.next();
|
||||
QStandardItem* lpItem = new QStandardItem(iterator.value());
|
||||
lpItem->setData(iterator.key());
|
||||
lpItem->setCheckable(true);
|
||||
|
||||
m_lpGenresModel->appendRow(lpItem);
|
||||
}
|
||||
}
|
||||
|
||||
cDiscover::~cDiscover()
|
||||
{
|
||||
delete ui;
|
||||
delete m_lpGenresModel;
|
||||
}
|
||||
|
||||
void cDiscover::spanChanged(int lower, int upper)
|
||||
{
|
||||
ui->m_lpVotingFrom->setText(QString::number((qreal)lower/10));
|
||||
ui->m_lpVotingTo->setText(QString::number((qreal)upper/10));
|
||||
}
|
||||
|
||||
void cDiscover::on_m_lpDiscover_clicked()
|
||||
{
|
||||
QString szText = ui->m_lpText->text();
|
||||
qint16 iYear = ui->m_lpYear->value();
|
||||
qreal voteMin = (qreal)ui->m_lpVoting->lowerValue()/10;
|
||||
qreal voteMax = (qreal)ui->m_lpVoting->upperValue()/10;
|
||||
|
||||
QList<qint32> genres;
|
||||
|
||||
if(!ui->m_lpYearEnable->isChecked())
|
||||
iYear = -1;
|
||||
|
||||
for(int x = 0;x < m_lpGenresModel->rowCount();x++)
|
||||
{
|
||||
QStandardItem* lpItem = m_lpGenresModel->item(x);
|
||||
|
||||
if(lpItem->checkState() == Qt::Checked)
|
||||
genres.append(lpItem->data().toInt());
|
||||
}
|
||||
|
||||
setCursor(Qt::WaitCursor);
|
||||
|
||||
cTheMovieDBV3 movieDB3;
|
||||
QList<cSerie*> serieList = movieDB3.discoverSerie(szText, iYear, genres, voteMin, voteMax, "de-DE");
|
||||
|
||||
m_lpSeriesModel->clear();
|
||||
|
||||
QStringList headerLabels = QStringList() << tr("Title") << tr("Year");
|
||||
m_lpSeriesModel->setHorizontalHeaderLabels(headerLabels);
|
||||
|
||||
for(int x = 0; x < serieList.count();x++)
|
||||
{
|
||||
cSerie* lpSerie = serieList[x];
|
||||
|
||||
if(m_serieList.find(lpSerie->seriesID()))
|
||||
continue;
|
||||
QList<QStandardItem*> items;
|
||||
|
||||
items.append(new QStandardItem(lpSerie->seriesName()));
|
||||
items.append(new QStandardItem(QString::number(lpSerie->firstAired().year())));
|
||||
items[0]->setData(QVariant::fromValue(lpSerie));
|
||||
items[1]->setData(QVariant::fromValue(lpSerie));
|
||||
items[0]->setCheckable(true);
|
||||
|
||||
m_lpSeriesModel->appendRow(items);
|
||||
}
|
||||
|
||||
for(int x = 0;x < headerLabels.count();x++)
|
||||
ui->m_lpSeries->resizeColumnToContents(x);
|
||||
|
||||
setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
void cDiscover::on_m_lpYearEnable_clicked(bool checked)
|
||||
{
|
||||
ui->m_lpYear->setEnabled(checked);
|
||||
}
|
||||
|
||||
void cDiscover::on_m_lpSeries_clicked(const QModelIndex &index)
|
||||
{
|
||||
QStandardItem* lpItem = m_lpSeriesModel->itemFromIndex(index);
|
||||
cSerie* lpSerie = lpItem->data().value<cSerie*>();
|
||||
|
||||
// if(lpSerie->cast().isEmpty())
|
||||
// {
|
||||
// cTheMovieDBV3 theMovieDB;
|
||||
// theMovieDB.loadCastSerie(lpSerie);
|
||||
// }
|
||||
// ui->m_lpMovieDetails->setMovie(lpMovie);
|
||||
}
|
||||
|
||||
QList<qint32> cDiscover::id()
|
||||
{
|
||||
QList<qint32> idList;
|
||||
|
||||
for(int x = 0;x < m_lpSeriesModel->rowCount();x++)
|
||||
{
|
||||
if(m_lpSeriesModel->item(x, 0)->checkState() == Qt::Checked)
|
||||
{
|
||||
cSerie* lpSerie = m_lpSeriesModel->item(x, 0)->data().value<cSerie*>();
|
||||
idList.append(lpSerie->seriesID());
|
||||
}
|
||||
}
|
||||
|
||||
return(idList);
|
||||
}
|
||||
|
||||
+16
-2
@@ -2,7 +2,10 @@
|
||||
#define CDISCOVER_H
|
||||
|
||||
|
||||
#include <cserie.h>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
@@ -14,11 +17,22 @@ class cDiscover : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit cDiscover(QWidget *parent = 0);
|
||||
explicit cDiscover(const cSerieList serieList, QWidget *parent = 0);
|
||||
~cDiscover();
|
||||
|
||||
QList<qint32> id();
|
||||
|
||||
private slots:
|
||||
void spanChanged(int lower, int upper);
|
||||
void on_m_lpDiscover_clicked();
|
||||
void on_m_lpYearEnable_clicked(bool checked);
|
||||
void on_m_lpSeries_clicked(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
Ui::cDiscover* ui;
|
||||
Ui::cDiscover* ui;
|
||||
QStandardItemModel* m_lpGenresModel;
|
||||
QStandardItemModel* m_lpSeriesModel;
|
||||
cSerieList m_serieList;
|
||||
};
|
||||
|
||||
#endif // CDISCOVER_H
|
||||
|
||||
+179
-22
@@ -1,38 +1,195 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<author/>
|
||||
<comment/>
|
||||
<exportmacro/>
|
||||
<class>cDiscover</class>
|
||||
<widget class="QDialog" name="cDiscover">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>900</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>240</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,10">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Text:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="m_lpText"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="m_lpYearEnable">
|
||||
<property name="text">
|
||||
<string>Erscheinungsjahr:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="m_lpYear">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1800</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>2100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,1,1">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Voting:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="m_lpVotingFrom">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="m_lpVotingTo">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QxtSpanSlider" name="m_lpVoting">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Genre</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QListView" name="m_lpGenres">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="flow">
|
||||
<enum>QListView::TopToBottom</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_lpDiscover">
|
||||
<property name="text">
|
||||
<string>Discover</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4" stretch="1,2">
|
||||
<item>
|
||||
<widget class="QTreeView" name="m_lpSeries">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="m_lpMovieDetailsScroller">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>579</width>
|
||||
<height>302</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="cMovieDetails" name="m_lpSerieDetails" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<pixmapfunction/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QxtSpanSlider</class>
|
||||
<extends>QSlider</extends>
|
||||
<header>qxtspanslider.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>cMovieDetails</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>cmoviedetails.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
+90
-6
@@ -2468,18 +2468,102 @@ void cMainWindow::onActionExit()
|
||||
|
||||
void cMainWindow::onActionDiscover()
|
||||
{
|
||||
cTheMovieDBV3 movieDB3;
|
||||
QMap<qint32, QString> genres;
|
||||
cDiscover* lpDiscover = new cDiscover(m_serieList, this);
|
||||
|
||||
genres = movieDB3.genresSerie("de-DE");
|
||||
QSettings settings;
|
||||
qint16 iX = settings.value("serieDiscover/x", QVariant::fromValue(-1)).toInt();
|
||||
qint16 iY = settings.value("serieDiscover/y", QVariant::fromValue(-1)).toInt();
|
||||
qint16 iWidth = settings.value("serieDiscover/width", QVariant::fromValue(-1)).toInt();
|
||||
qint16 iHeight = settings.value("serieDiscover/height", QVariant::fromValue(-1)).toInt();
|
||||
|
||||
if(iX != -1 && iY != -1)
|
||||
lpDiscover->move(iX, iY);
|
||||
if(iWidth != -1 && iHeight != -1)
|
||||
lpDiscover->resize(iWidth, iHeight);
|
||||
|
||||
if(lpDiscover->exec() == QDialog::Rejected)
|
||||
{
|
||||
delete lpDiscover;
|
||||
return;
|
||||
}
|
||||
|
||||
settings.setValue("serieDiscover/width", QVariant::fromValue(lpDiscover->size().width()));
|
||||
settings.setValue("serieDiscover/height", QVariant::fromValue(lpDiscover->size().height()));
|
||||
settings.setValue("serieDiscover/x", QVariant::fromValue(lpDiscover->x()));
|
||||
settings.setValue("serieDiscover/y", QVariant::fromValue(lpDiscover->y()));
|
||||
|
||||
QList<qint32> idList = lpDiscover->id();
|
||||
|
||||
delete lpDiscover;
|
||||
}
|
||||
|
||||
void cMainWindow::onActionMovieDiscover()
|
||||
{
|
||||
cMovieDiscover* lpMovieDiscover;
|
||||
cMovieDiscover* lpMovieDiscover = new cMovieDiscover(m_movieList, this);
|
||||
|
||||
lpMovieDiscover = new cMovieDiscover(m_movieList, this);
|
||||
lpMovieDiscover->exec();
|
||||
QSettings settings;
|
||||
qint16 iX = settings.value("movieDiscover/x", QVariant::fromValue(-1)).toInt();
|
||||
qint16 iY = settings.value("movieDiscover/y", QVariant::fromValue(-1)).toInt();
|
||||
qint16 iWidth = settings.value("movieDiscover/width", QVariant::fromValue(-1)).toInt();
|
||||
qint16 iHeight = settings.value("movieDiscover/height", QVariant::fromValue(-1)).toInt();
|
||||
|
||||
if(iX != -1 && iY != -1)
|
||||
lpMovieDiscover->move(iX, iY);
|
||||
if(iWidth != -1 && iHeight != -1)
|
||||
lpMovieDiscover->resize(iWidth, iHeight);
|
||||
|
||||
if(lpMovieDiscover->exec() == QDialog::Rejected)
|
||||
{
|
||||
delete lpMovieDiscover;
|
||||
return;
|
||||
}
|
||||
|
||||
settings.setValue("movieDiscover/width", QVariant::fromValue(lpMovieDiscover->size().width()));
|
||||
settings.setValue("movieDiscover/height", QVariant::fromValue(lpMovieDiscover->size().height()));
|
||||
settings.setValue("movieDiscover/x", QVariant::fromValue(lpMovieDiscover->x()));
|
||||
settings.setValue("movieDiscover/y", QVariant::fromValue(lpMovieDiscover->y()));
|
||||
|
||||
QList<qint32> idList = lpMovieDiscover->id();
|
||||
|
||||
delete lpMovieDiscover;
|
||||
|
||||
cMovie* lpMovie = 0;
|
||||
|
||||
for(int x = 0;x < idList.count();x++)
|
||||
{
|
||||
qint32 id = idList.at(x);
|
||||
if(id != -1)
|
||||
{
|
||||
cMessageAnimateDialog* lpDialog = new cMessageAnimateDialog(this);
|
||||
lpDialog->setTitle("Refresh");
|
||||
lpDialog->setMessage("Loading");
|
||||
lpDialog->show();
|
||||
|
||||
cTheMovieDBV3 movieDB3;
|
||||
|
||||
lpMovie = movieDB3.loadMovie(id, "de-DE");
|
||||
if(!lpMovie)
|
||||
lpMovie = movieDB3.loadMovie(id, "en");
|
||||
|
||||
delete lpDialog;
|
||||
|
||||
if(runMovieEdit(lpMovie))
|
||||
{
|
||||
lpDialog = new cMessageAnimateDialog(this);
|
||||
lpDialog->setTitle("Update");
|
||||
lpDialog->setMessage("Updating");
|
||||
lpDialog->show();
|
||||
|
||||
lpMovie->loadFanart();
|
||||
lpMovie->save(m_db);
|
||||
|
||||
delete lpDialog;
|
||||
}
|
||||
delete lpMovie;
|
||||
}
|
||||
}
|
||||
|
||||
loadMoviesDB();
|
||||
displayMovies();
|
||||
applyMoviesFilter();
|
||||
}
|
||||
|
||||
+16
-1
@@ -31,7 +31,6 @@ cMovieDiscover::cMovieDiscover(const cMovieList movieList, QWidget *parent) :
|
||||
headerLabels = QStringList() << tr("Title") << tr("Year");
|
||||
m_lpMoviesModel->setHorizontalHeaderLabels(headerLabels);
|
||||
|
||||
|
||||
connect(ui->m_lpVoting, &QxtSpanSlider::spanChanged, this, &cMovieDiscover::spanChanged);
|
||||
|
||||
ui->m_lpVoting->setRange(0, 100);
|
||||
@@ -138,3 +137,19 @@ void cMovieDiscover::on_m_lpMovies_clicked(const QModelIndex &index)
|
||||
}
|
||||
ui->m_lpMovieDetails->setMovie(lpMovie);
|
||||
}
|
||||
|
||||
QList<qint32> cMovieDiscover::id()
|
||||
{
|
||||
QList<qint32> idList;
|
||||
|
||||
for(int x = 0;x < m_lpMoviesModel->rowCount();x++)
|
||||
{
|
||||
if(m_lpMoviesModel->item(x, 0)->checkState() == Qt::Checked)
|
||||
{
|
||||
cMovie* lpMovie = m_lpMoviesModel->item(x, 0)->data().value<cMovie*>();
|
||||
idList.append(lpMovie->movieID());
|
||||
}
|
||||
}
|
||||
|
||||
return(idList);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
explicit cMovieDiscover(const cMovieList movieList, QWidget *parent = 0);
|
||||
~cMovieDiscover();
|
||||
|
||||
QList<qint32> id();
|
||||
private slots:
|
||||
void spanChanged(int lower, int upper);
|
||||
void on_m_lpDiscover_clicked();
|
||||
|
||||
@@ -799,3 +799,124 @@ void cTheMovieDBV3::loadCastMovie(cMovie* lpMovie)
|
||||
lpMovie->setCrew(szCrew);
|
||||
}
|
||||
}
|
||||
|
||||
QList<cSerie*> cTheMovieDBV3::discoverSerie(const QString& szText, const qint16& iYear, const QList<qint32>& genres, const qreal& voteMin, const qreal& voteMax, const QString& szLanguage)
|
||||
{
|
||||
if(m_genres.isEmpty())
|
||||
m_genres = genresMovie("de-DE");
|
||||
|
||||
QList<cSerie*> serieList;
|
||||
QNetworkAccessManager networkManager;
|
||||
QString szRequest = QString("https://api.themoviedb.org/3/discover/tv?api_key=%1").arg(m_szToken);
|
||||
qint16 page = 1;
|
||||
|
||||
if(!szLanguage.contains("all"))
|
||||
szRequest.append(QString("&language=%1").arg(szLanguage));
|
||||
|
||||
if(!szText.isEmpty())
|
||||
szRequest.append(QString("&with_keywords=%1").arg(szText));
|
||||
if(iYear != -1)
|
||||
szRequest.append(QString("&first_air_date_year=%1").arg(iYear));
|
||||
if(genres.count())
|
||||
{
|
||||
QString tmp = QString::number(genres[0]);
|
||||
|
||||
for(int x = 1;x < genres.count();x++)
|
||||
tmp.append(QString(",%1").arg(genres[x]));
|
||||
szRequest.append(QString("&with_genres=%1").arg(tmp));
|
||||
}
|
||||
szRequest.append(QString("&vote_average.gte=%1").arg(voteMin));
|
||||
szRequest.append(QString("&vote_average.lte=%1").arg(voteMax));
|
||||
|
||||
for(;;)
|
||||
{
|
||||
QNetworkRequest request(QUrl(QString("%1&page=%2").arg(szRequest).arg(page)));
|
||||
|
||||
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["results"].toArray();
|
||||
QJsonArray tmpArray;
|
||||
QStringList tmpList;
|
||||
|
||||
for(int z = 0;z < jsonArray.count();z++)
|
||||
{
|
||||
QJsonObject serie = jsonArray[z].toObject();
|
||||
cSerie* lpSerie = new cSerie;
|
||||
|
||||
lpSerie->setSeriesID(serie["id"].toInt());
|
||||
lpSerie->setBackdropPath(serie["backdrop_path"].toString());
|
||||
tmpArray = serie["created_by"].toArray();
|
||||
for(int x = 0;x < tmpArray.count();x++)
|
||||
tmpList.append(tmpArray.at(x).toObject()["name"].toString());
|
||||
lpSerie->setCreatedBy(tmpList);
|
||||
tmpList.clear();
|
||||
lpSerie->setFirstAired(serie["first_air_date"].toString());
|
||||
tmpArray = serie["genres"].toArray();
|
||||
for(int x = 0;x < tmpArray.count();x++)
|
||||
tmpList.append(tmpArray.at(x).toObject()["name"].toString());
|
||||
lpSerie->setGenre(tmpList);
|
||||
tmpList.clear();
|
||||
lpSerie->setHomepage(serie["homepage"].toString());
|
||||
lpSerie->setLastAired(serie["last_air_date"].toString());
|
||||
tmpArray = serie["languages"].toArray();
|
||||
for(int x = 0;x < tmpArray.count();x++)
|
||||
tmpList.append(tmpArray.at(x).toString());
|
||||
lpSerie->setLanguages(tmpList);
|
||||
tmpList.clear();
|
||||
lpSerie->setSeriesName(serie["name"].toString());
|
||||
tmpArray = serie["networks"].toArray();
|
||||
for(int x = 0;x < tmpArray.count();x++)
|
||||
tmpList.append(tmpArray.at(x).toObject()["name"].toString());
|
||||
lpSerie->setNetworks(tmpList);
|
||||
tmpList.clear();
|
||||
lpSerie->setEpisodes(serie["number_of_episodes"].toInt());
|
||||
lpSerie->setSeasons(serie["number_of_seasons"].toInt());
|
||||
tmpArray = serie["origin_country"].toArray();
|
||||
for(int x = 0;x < tmpArray.count();x++)
|
||||
tmpList.append(tmpArray.at(x).toString());
|
||||
lpSerie->setOriginCountries(tmpList);
|
||||
tmpList.clear();
|
||||
lpSerie->setOriginalLanguage(serie["original_language"].toString());
|
||||
lpSerie->setOriginalName(serie["original_name"].toString());
|
||||
lpSerie->setOverview(serie["overview"].toString());
|
||||
lpSerie->setPopularity(serie["popularity"].toDouble());
|
||||
lpSerie->setPosterPath(serie["poster_path"].toString());
|
||||
tmpArray = serie["production_companies"].toArray();
|
||||
for(int x = 0;x < tmpArray.count();x++)
|
||||
tmpList.append(tmpArray.at(x).toObject()["name"].toString());
|
||||
lpSerie->setProductionCompanies(tmpList);
|
||||
tmpList.clear();
|
||||
lpSerie->setStatus(serie["status"].toString());
|
||||
lpSerie->setType(serie["type"].toString());
|
||||
lpSerie->setVoteAverage(serie["vote_average"].toDouble());
|
||||
lpSerie->setVoteCount(serie["vote_count"].toInt());
|
||||
|
||||
serieList.append(lpSerie);
|
||||
}
|
||||
if(jsonObj["total_pages"].toInt() == page)
|
||||
break;
|
||||
|
||||
page++;
|
||||
if(page > 20)
|
||||
break;
|
||||
|
||||
delete reply;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << reply->errorString();
|
||||
delete reply;
|
||||
}
|
||||
}
|
||||
|
||||
return(serieList);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
cSerie* loadSerie(const qint32 &iID, const QString& szLanguage);
|
||||
cSerie* loadSerie(const QString& szIMDBID);
|
||||
QMap<qint32, QString> genresSerie(const QString& szLanguage = "all");
|
||||
QList<cSerie*> discoverSerie(const QString& szText, const qint16& iYear, const QList<qint32>& genres, const qreal& voteMin, const qreal& voteMax, const QString& szLanguage = "all");
|
||||
private:
|
||||
QString m_szToken;
|
||||
QMap<qint32, QString> m_genres;
|
||||
|
||||
Reference in New Issue
Block a user