]> git.sur5r.net Git - minitube/blob - src/yt/ytjs/ytjschannel.cpp
New upstream version 3.8
[minitube] / src / yt / ytjs / ytjschannel.cpp
1 #include "ytjschannel.h"
2
3 #include "js.h"
4
5 YTJSChannel::YTJSChannel(const QString &id, QObject *parent) : QObject(parent) {
6     load(id);
7 }
8
9 void YTJSChannel::load(const QString &channelId) {
10     JS::instance()
11             .callFunction(new JSResult(this), "channelInfo", {channelId})
12             .onJson([this](auto &doc) {
13                 auto obj = doc.object();
14
15                 displayName = obj["author"].toString();
16                 description = obj["description"].toString();
17
18                 const auto thumbs = obj["authorThumbnails"].toArray();
19                 int maxFoundWidth = 0;
20                 for (const auto &thumbObj : thumbs) {
21                     QString url = thumbObj["url"].toString();
22                     int width = thumbObj["width"].toInt();
23                     if (width > maxFoundWidth) {
24                         maxFoundWidth = width;
25                         thumbnailUrl = url;
26                     }
27                 }
28
29                 emit loaded();
30             })
31             .onError([this](auto &msg) { emit error(msg); });
32 }