1 #include "ivsinglevideosource.h"
8 #include "ivlistparser.h"
10 IVSingleVideoSource::IVSingleVideoSource(QObject *parent)
11 : IVVideoSource(parent), video(nullptr), startIndex(0), max(0) {}
13 void IVSingleVideoSource::reallyLoadVideos(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 auto reply = Invidious::cachedHttp().get(url);
43 connect(reply, SIGNAL(data(QByteArray)), SLOT(parseResults(QByteArray)));
44 connect(reply, &HttpReply::error, this, &IVSingleVideoSource::handleError);
47 void IVSingleVideoSource::parseResults(QByteArray data) {
50 QJsonDocument doc = QJsonDocument::fromJson(data);
51 const QJsonArray items = doc.object()["recommendedVideos"].toArray();
53 IVListParser parser(items);
54 const QVector<Video *> &videos = parser.getVideos();
56 emit gotVideos(videos);
58 loadVideos(max - 1, 2);
59 else if (startIndex == 2)
60 emit finished(videos.size() + 1);
62 emit finished(videos.size());
65 QString IVSingleVideoSource::getName() {
69 void IVSingleVideoSource::setVideo(Video *video) {
71 videoId = video->getId();