X-Git-Url: https://git.sur5r.net/?p=minitube;a=blobdiff_plain;f=src%2Fyt%2Fytjs%2Fytjschannel.cpp;fp=src%2Fyt%2Fytjs%2Fytjschannel.cpp;h=e6ccdd30238f0e5421284d2c258222058181cbe8;hp=0000000000000000000000000000000000000000;hb=b4e0b70c51f05c19b9095a381cb73bfb79f128dd;hpb=b76332aa9817cd134abf7e7e89e62456c1116668 diff --git a/src/yt/ytjs/ytjschannel.cpp b/src/yt/ytjs/ytjschannel.cpp new file mode 100644 index 0000000..e6ccdd3 --- /dev/null +++ b/src/yt/ytjs/ytjschannel.cpp @@ -0,0 +1,32 @@ +#include "ytjschannel.h" + +#include "js.h" + +YTJSChannel::YTJSChannel(const QString &id, QObject *parent) : QObject(parent) { + load(id); +} + +void YTJSChannel::load(const QString &channelId) { + JS::instance() + .callFunction(new JSResult(this), "channelInfo", {channelId}) + .onJson([this](auto &doc) { + auto obj = doc.object(); + + displayName = obj["author"].toString(); + description = obj["description"].toString(); + + const auto thumbs = obj["authorThumbnails"].toArray(); + int maxFoundWidth = 0; + for (const auto &thumbObj : thumbs) { + QString url = thumbObj["url"].toString(); + int width = thumbObj["width"].toInt(); + if (width > maxFoundWidth) { + maxFoundWidth = width; + thumbnailUrl = url; + } + } + + emit loaded(); + }) + .onError([this](auto &msg) { emit error(msg); }); +}