]> git.sur5r.net Git - minitube/blobdiff - src/yt/ytjs/ytjschannel.cpp
Update upstream source from tag 'upstream/3.8'
[minitube] / src / yt / ytjs / ytjschannel.cpp
diff --git a/src/yt/ytjs/ytjschannel.cpp b/src/yt/ytjs/ytjschannel.cpp
new file mode 100644 (file)
index 0000000..e6ccdd3
--- /dev/null
@@ -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); });
+}