Skip to content

Commit

Permalink
Merge pull request #12 from kenter7317/master
Browse files Browse the repository at this point in the history
Chzzk 채널 구독자용 이모티콘 가져오기
  • Loading branch information
R2turnTrue authored Sep 12, 2024
2 parents eeed52b + 7907b80 commit f13a8e1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/xyz/r2turntrue/chzzk4j/Chzzk.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import xyz.r2turntrue.chzzk4j.types.ChzzkFollowingStatusResponse;
import xyz.r2turntrue.chzzk4j.types.ChzzkUser;
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannel;
import xyz.r2turntrue.chzzk4j.types.channel.emoticon.ChzzkChannelEmotePackData;
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannelFollowingData;
import xyz.r2turntrue.chzzk4j.types.channel.ChzzkChannelRules;
import xyz.r2turntrue.chzzk4j.types.channel.recommendation.ChzzkRecommendationChannels;
import xyz.r2turntrue.chzzk4j.util.RawApiUtils;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.List;

public class Chzzk {
public static String API_URL = "https://api.chzzk.naver.com";
Expand Down Expand Up @@ -101,7 +102,6 @@ public ChzzkChannel getChannel(String channelId) throws IOException, ChannelNotE
ChzzkChannel channel = gson.fromJson(
contentJson,
ChzzkChannel.class);

if (channel.getChannelId() == null) {
throw new ChannelNotExistsException("The channel does not exists!");
}
Expand Down Expand Up @@ -134,6 +134,24 @@ public ChzzkChannelRules getChannelChatRules(String channelId) throws IOExceptio
return rules;
}

public ChzzkChannelEmotePackData getChannelEmotePackData(String channelId) throws IOException {
JsonElement contentJson = RawApiUtils.getContentJson(
httpClient,
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId + "/emoji-packs").build(),
isDebug);
ChzzkChannelEmotePackData emoticons = null;
List<JsonElement> emoteElements = contentJson.getAsJsonObject().asMap().get("subscriptionEmojiPacks").getAsJsonArray().asList();
for (JsonElement emoteElement : emoteElements) {
if (emoteElement.getAsJsonObject().asMap().get("emojiPackId").getAsString().equals("\""+channelId+ "\"")) {
continue;
}
emoticons= gson.fromJson(
emoteElement,
ChzzkChannelEmotePackData.class);
}
return emoticons;
}

/**
* Get following status about channel.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.Nullable;
import xyz.r2turntrue.chzzk4j.Chzzk;
import xyz.r2turntrue.chzzk4j.exception.NotExistsException;
import xyz.r2turntrue.chzzk4j.types.channel.emoticon.ChzzkChannelEmotePackData;

import java.io.IOException;

Expand All @@ -12,6 +13,7 @@ public class ChzzkPartialChannel {
private String channelImageUrl;
private boolean verifiedMark;
private ChzzkChannelPersonalData personalData;
private ChzzkChannelEmotePackData emotePackData;

ChzzkPartialChannel() {}

Expand Down Expand Up @@ -64,6 +66,13 @@ public ChzzkChannelPersonalData getPersonalData() {
return personalData;
}

/**
* Get the emoticon pack data of the channel.
*/
@Nullable
public ChzzkChannelEmotePackData getEmotePackData() {
return emotePackData;
}
@Override
public String toString() {
return "ChzzkPartialChannel{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package xyz.r2turntrue.chzzk4j.types.channel.emoticon;

import java.util.List;

public class ChzzkChannelEmotePackData {
private String emojiPackId;
private String emojiPackName;
private String emojiPackImageUrl;
private boolean emojiPackLocked;
private List<ChzzkChannelEmoticonData> emojis;

private ChzzkChannelEmotePackData() {}

/**
* Get the pack's id.
*/
public String getPackId() {
return emojiPackId;
}

/**
* Get the name of the pack.
*/
public String getPackName() {
return emojiPackName;
}

/**
* Get url of the pack's image.
*/
public String getPackImageUrl() {
return emojiPackImageUrl;
}

/**
* Get the emoticons data of the pack.
*/

public List<ChzzkChannelEmoticonData> getEmojis() {
return emojis;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xyz.r2turntrue.chzzk4j.types.channel.emoticon;

public class ChzzkChannelEmoticonData {
private String emojiId;
private String imageUrl;

private ChzzkChannelEmoticonData() {}

/**
* Get the emoticon's id.
*/
public String getEmoticonId() {
return emojiId;
}

/**
* Get url of the emoticon's image.
*/
public String getEmoticonImageUrl() {
return imageUrl;
}
}

0 comments on commit f13a8e1

Please sign in to comment.