1 #include "ivsinglevideosource.h"
8 #include "ivlistparser.h"
10 IVSingleVideoSource::IVSingleVideoSource(QObject *parent)
11 : VideoSource(parent), video(nullptr), startIndex(0), max(0) {}
13 void IVSingleVideoSource::loadVideos(int max, int startIndex) {
15 this->startIndex = startIndex;
20 if (startIndex == 1) {
22 QVector<Video *> videos;
23 videos << video->clone();
25 name = videos.at(0)->getTitle();
26 qDebug() << "Emitting name changed" << name;
27 emit nameChanged(name);
29 emit gotVideos(videos);
30 loadVideos(max - 1, 2);
34 url = Invidious::instance().method("videos/");
35 url.setPath(url.path() + videoId);
38 url = Invidious::instance().method("videos");
39 url.setPath(url.path() + "/" + videoId);
42 QObject *reply = Invidious::cachedHttp().get(url);
43 connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray)));
44 connect(reply, SIGNAL(error(QString)), SLOT(requestError(QString)));
47 void IVSingleVideoSource::parseResults(QByteArray data) {
50 QJsonDocument doc = QJsonDocument::fromJson(data);
51 const QJsonArray items = doc.object()["recommendedVideos"].toArray();
52 IVListParser parser(items);
53 const QVector<Video *> &videos = parser.getVideos();
55 emit gotVideos(videos);
57 loadVideos(max - 1, 2);
58 else if (startIndex == 2)
59 emit finished(videos.size() + 1);
61 emit finished(videos.size());
64 void IVSingleVideoSource::abort() {
68 QString IVSingleVideoSource::getName() {
72 void IVSingleVideoSource::setVideo(Video *video) {
74 videoId = video->getId();
77 void IVSingleVideoSource::requestError(const QString &message) {