mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
global ffz and bttv now uses new NetworkRequest
This commit is contained in:
parent
13b39e374b
commit
a6be0c83bc
|
@ -399,96 +399,77 @@ void EmoteManager::refreshTwitchEmotes(const std::shared_ptr<twitch::TwitchUser>
|
||||||
emoteData.filled = true;
|
emoteData.filled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteManager::loadBTTVEmotes()
|
void EmoteManager::loadBTTVEmotes()
|
||||||
{
|
{
|
||||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
QString url("https://api.betterttv.net/2/emotes");
|
||||||
|
|
||||||
QUrl url("https://api.betterttv.net/2/emotes");
|
util::NetworkRequest req(url);
|
||||||
QNetworkRequest request(url);
|
req.setCaller(QThread::currentThread());
|
||||||
|
req.setTimeout(30000);
|
||||||
|
req.getJSON([this](QJsonObject &root) {
|
||||||
|
debug::Log("Got global bttv emotes");
|
||||||
|
auto emotes = root.value("emotes").toArray();
|
||||||
|
|
||||||
QNetworkReply *reply = manager->get(request);
|
QString linkTemplate = "https:" + root.value("urlTemplate").toString();
|
||||||
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
std::vector<std::string> codes;
|
||||||
if (reply->error() == QNetworkReply::NetworkError::NoError) {
|
for (const QJsonValue &emote : emotes) {
|
||||||
QByteArray data = reply->readAll();
|
QString id = emote.toObject().value("id").toString();
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
QString code = emote.toObject().value("code").toString();
|
||||||
QJsonObject root = jsonDoc.object();
|
// emote.value("imageType").toString();
|
||||||
|
|
||||||
auto emotes = root.value("emotes").toArray();
|
QString tmp = linkTemplate;
|
||||||
|
tmp.detach();
|
||||||
|
QString url = tmp.replace("{{id}}", id).replace("{{image}}", "1x");
|
||||||
|
|
||||||
QString linkTemplate = "https:" + root.value("urlTemplate").toString();
|
this->bttvGlobalEmotes.insert(
|
||||||
|
code, new LazyLoadedImage(url, 1, code, code + "<br/>Global BTTV Emote"));
|
||||||
std::vector<std::string> codes;
|
codes.push_back(code.toStdString());
|
||||||
for (const QJsonValue &emote : emotes) {
|
|
||||||
QString id = emote.toObject().value("id").toString();
|
|
||||||
QString code = emote.toObject().value("code").toString();
|
|
||||||
// emote.value("imageType").toString();
|
|
||||||
|
|
||||||
QString tmp = linkTemplate;
|
|
||||||
tmp.detach();
|
|
||||||
QString url = tmp.replace("{{id}}", id).replace("{{image}}", "1x");
|
|
||||||
|
|
||||||
this->bttvGlobalEmotes.insert(
|
|
||||||
code, new LazyLoadedImage(url, 1, code, code + "<br/>Global BTTV Emote"));
|
|
||||||
codes.push_back(code.toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
this->bttvGlobalEmoteCodes = codes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
this->bttvGlobalEmoteCodes = codes;
|
||||||
manager->deleteLater();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteManager::loadFFZEmotes()
|
void EmoteManager::loadFFZEmotes()
|
||||||
{
|
{
|
||||||
QNetworkAccessManager *manager = new QNetworkAccessManager();
|
QString url("https://api.frankerfacez.com/v1/set/global");
|
||||||
|
|
||||||
QUrl url("https://api.frankerfacez.com/v1/set/global");
|
util::NetworkRequest req(url);
|
||||||
QNetworkRequest request(url);
|
req.setCaller(QThread::currentThread());
|
||||||
|
req.setTimeout(30000);
|
||||||
|
req.getJSON([this](QJsonObject &root) {
|
||||||
|
debug::Log("Got global ffz emotes");
|
||||||
|
|
||||||
QNetworkReply *reply = manager->get(request);
|
auto sets = root.value("sets").toObject();
|
||||||
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
std::vector<std::string> codes;
|
||||||
if (reply->error() == QNetworkReply::NetworkError::NoError) {
|
for (const QJsonValue &set : sets) {
|
||||||
QByteArray data = reply->readAll();
|
auto emoticons = set.toObject().value("emoticons").toArray();
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
|
||||||
QJsonObject root = jsonDoc.object();
|
|
||||||
|
|
||||||
auto sets = root.value("sets").toObject();
|
for (const QJsonValue &emote : emoticons) {
|
||||||
|
QJsonObject object = emote.toObject();
|
||||||
|
|
||||||
std::vector<std::string> codes;
|
// margins
|
||||||
for (const QJsonValue &set : sets) {
|
|
||||||
auto emoticons = set.toObject().value("emoticons").toArray();
|
|
||||||
|
|
||||||
for (const QJsonValue &emote : emoticons) {
|
// int id = object.value("id").toInt();
|
||||||
QJsonObject object = emote.toObject();
|
QString code = object.value("name").toString();
|
||||||
|
|
||||||
// margins
|
QJsonObject urls = object.value("urls").toObject();
|
||||||
|
QString url1 = "http:" + urls.value("1").toString();
|
||||||
|
|
||||||
// int id = object.value("id").toInt();
|
this->ffzGlobalEmotes.insert(
|
||||||
QString code = object.value("name").toString();
|
code, new LazyLoadedImage(url1, 1, code, code + "<br/>Global FFZ Emote"));
|
||||||
|
codes.push_back(code.toStdString());
|
||||||
QJsonObject urls = object.value("urls").toObject();
|
|
||||||
QString url1 = "http:" + urls.value("1").toString();
|
|
||||||
|
|
||||||
this->ffzGlobalEmotes.insert(
|
|
||||||
code, new LazyLoadedImage(url1, 1, code, code + "<br/>Global FFZ Emote"));
|
|
||||||
codes.push_back(code.toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
this->ffzGlobalEmoteCodes = codes;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
reply->deleteLater();
|
this->ffzGlobalEmoteCodes = codes;
|
||||||
manager->deleteLater();
|
}
|
||||||
});
|
});
|
||||||
}
|
} // namespace chatterino
|
||||||
|
|
||||||
// id is used for lookup
|
// id is used for lookup
|
||||||
// emoteName is used for giving a name to the emote in case it doesn't exist
|
// emoteName is used for giving a name to the emote in case it doesn't exist
|
||||||
|
|
Loading…
Reference in a new issue