]> git.sur5r.net Git - minitube/blob - src/yt/ytjs/ytjschannel.cpp
de0e8e3bcba6474c2961455a03b716a486bdc471
[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                     int width = thumbObj["width"].toInt();
22                     if (width > maxFoundWidth) {
23                         maxFoundWidth = width;
24                         QString url = thumbObj["url"].toString();
25                         thumbnailUrl = url;
26                     }
27                 }
28
29                 emit loaded();
30             })
31             .onError([this](auto &msg) { emit error(msg); });
32 }