Search in sources :

Example 1 with BttvEmote

use of com.glitchcog.fontificator.emoji.loader.betterttv.BttvEmote in project ChatGameFontificator by GlitchCog.

the class EmojiParser method parseBetterTtvEmoteJson.

/**
     * Parse emotes loaded using the BetterTTV emote API
     * 
     * @param emoji
     * @param jsonData
     * @param isGlobal
     *            Whether the BetterTTV emotes to be loaded are the BetterTTV global emotes
     * @throws IOException
     */
private void parseBetterTtvEmoteJson(TypedEmojiMap emoji, String jsonData, boolean isGlobal) throws IOException {
    JsonParser jp = new JsonParser();
    JsonObject root = jp.parse(jsonData).getAsJsonObject();
    if (root.get("emotes").isJsonNull()) {
        logBox.log("Unable to load Better TTV global emotes");
        return;
    }
    Gson gson = new Gson();
    Type emoteType = new TypeToken<BttvEmote[]>() {
    }.getType();
    final String urlTemplate = "https:" + root.get("urlTemplate").getAsString().replace("{{image}}", "2x");
    BttvEmote[] bttvEmotes = gson.fromJson(root.get("emotes").getAsJsonArray(), emoteType);
    int bttvCount = 0;
    for (BttvEmote be : bttvEmotes) {
        LazyLoadEmoji lle = new LazyLoadEmoji(be.getCode(), urlTemplate.replace("{{id}}", be.getId()), isGlobal ? EmojiType.BETTER_TTV_GLOBAL : EmojiType.BETTER_TTV_CHANNEL);
        lle.setAnimatedGif(AnimatedGifUtil.GIF_EXTENSION.equals(be.getImageType()));
        emoji.put(be.getCode(), lle);
        bttvCount++;
    }
    logBox.log(bttvCount + " Better TTV emote" + (bttvCount == 1 ? "" : "s") + " found");
}
Also used : LazyLoadEmoji(com.glitchcog.fontificator.emoji.LazyLoadEmoji) EmojiType(com.glitchcog.fontificator.emoji.EmojiType) UserType(com.glitchcog.fontificator.bot.UserType) Type(java.lang.reflect.Type) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonParser(com.google.gson.JsonParser) BttvEmote(com.glitchcog.fontificator.emoji.loader.betterttv.BttvEmote)

Aggregations

UserType (com.glitchcog.fontificator.bot.UserType)1 EmojiType (com.glitchcog.fontificator.emoji.EmojiType)1 LazyLoadEmoji (com.glitchcog.fontificator.emoji.LazyLoadEmoji)1 BttvEmote (com.glitchcog.fontificator.emoji.loader.betterttv.BttvEmote)1 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Type (java.lang.reflect.Type)1