Skip to content

Commit

Permalink
치지직 API 변동으로 인한 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
R2turnTrue committed Jan 15, 2024
1 parent bfc0aef commit 826d782
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# chzzk4j

![](https://img.shields.io/maven-central/v/io.github.R2turnTrue/chzzk4j)
[Example Minecraft Plugin](https://github.com/R2turnTrue/chzzk4j_demo)
![](https://img.shields.io/maven-central/v/io.github.R2turnTrue/chzzk4j) /
[Example Minecraft Plugin](https://github.com/R2turnTrue/chzzk4j_demo) /
[Discord Server](https://discord.gg/gtJ265XZWn)

Unofficial Java API library of CHZZK (치지직, the video streaming service of Naver)

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "io.github.R2turnTrue"
version = "0.0.1"
version = "0.0.2"

val publishProps = Properties()
publishProps.load(
Expand Down Expand Up @@ -50,7 +50,7 @@ publishing {
artifactId = "chzzk4j"
groupId = "io.github.R2turnTrue"

version = "0.0.1"
version = "0.0.2"

from(components["java"])

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/xyz/r2turntrue/chzzk4j/Chzzk.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public OkHttpClient getHttpClient() {
public ChzzkChannel getChannel(String channelId) throws IOException, ChannelNotExistsException {
JsonElement contentJson = RawApiUtils.getContentJson(
httpClient,
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId).build());
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId).build(),
isDebug);

ChzzkChannel channel = gson.fromJson(
contentJson,
Expand All @@ -107,7 +108,8 @@ public ChzzkChannel getChannel(String channelId) throws IOException, ChannelNotE
public ChzzkChannelRules getChannelChatRules(String channelId) throws IOException, NotExistsException {
JsonElement contentJson = RawApiUtils.getContentJson(
httpClient,
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId + "/chat-rules").build());
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId + "/chat-rules").build(),
isDebug);

ChzzkChannelRules rules = gson.fromJson(
contentJson,
Expand Down Expand Up @@ -136,7 +138,8 @@ public ChzzkChannelFollowingData getFollowingStatus(String channelId) throws IOE

JsonElement contentJson = RawApiUtils.getContentJson(
httpClient,
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId + "/follow").build());
RawApiUtils.httpGetRequest(API_URL + "/service/v1/channels/" + channelId + "/follow").build(),
isDebug);

ChzzkFollowingStatusResponse followingDataResponse = gson.fromJson(
contentJson,
Expand All @@ -163,7 +166,8 @@ public ChzzkUser getLoggedUser() throws IOException, NotLoggedInException {

JsonElement contentJson = RawApiUtils.getContentJson(
httpClient,
RawApiUtils.httpGetRequest(GAME_API_URL + "/v1/user/getUserStatus").build());
RawApiUtils.httpGetRequest(GAME_API_URL + "/v1/user/getUserStatus").build(),
isDebug);

ChzzkUser user = gson.fromJson(
contentJson,
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/xyz/r2turntrue/chzzk4j/chat/ChzzkChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void sendChat(String content) {

public void connectFromChannelId(String channelId) throws IOException {
String chatId = RawApiUtils.getContentJson(chzzk.getHttpClient(),
RawApiUtils.httpGetRequest(Chzzk.API_URL + "/service/v1/channels/" + channelId + "/live-detail").build())
RawApiUtils.httpGetRequest(Chzzk.API_URL + "/service/v2/channels/" + channelId + "/live-detail").build(), chzzk.isDebug)
.getAsJsonObject()
.get("chatChannelId")
.getAsString();
Expand Down Expand Up @@ -78,7 +78,8 @@ void connectFromChatId(String channelId, String chatId) throws IOException {
"&chatType=STREAMING";
accessToken = RawApiUtils.getContentJson(
chzzk.getHttpClient(),
RawApiUtils.httpGetRequest(accessTokenUrl).build()
RawApiUtils.httpGetRequest(accessTokenUrl).build(),
chzzk.isDebug
).getAsJsonObject().get("accessToken").getAsString();

int serverId = 0;
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/xyz/r2turntrue/chzzk4j/util/RawApiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@ public static Request.Builder httpGetRequest(String url) {
.get();
}

public static JsonObject getRawJson(OkHttpClient httpClient, Request request) throws IOException {
public static JsonObject getRawJson(OkHttpClient httpClient, Request request, boolean isDebug) throws IOException {
Response response = httpClient.newCall(request).execute();

if (response.isSuccessful()) {
ResponseBody body = response.body();
assert body != null;
String bodyString = body.string();
//System.out.println("BD: " + bodyString);
//\System.out.println("BD: " + bodyString);

return JsonParser.parseString(bodyString).getAsJsonObject();
} else {
System.err.println(response);
if (isDebug) {
ResponseBody body = response.body();
if (body != null) {
String bodyString = body.string();
System.out.println("BD: " + bodyString);
}
}
throw new IOException("Response was not successful!");
}
}

public static JsonElement getContentJson(OkHttpClient httpClient, Request request) throws IOException {
return getRawJson(httpClient, request).get("content");
public static JsonElement getContentJson(OkHttpClient httpClient, Request request, boolean isDebug) throws IOException {
return getRawJson(httpClient, request, isDebug).get("content");
}
}
5 changes: 3 additions & 2 deletions src/test/java/ChatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ public class ChatTest extends ChzzkTestBase {
@Test
void testingChat() throws IOException, InterruptedException {
ChzzkChat chat = loginChzzk.chat();
chat.connectFromChannelId("ec94e63170d15e8e8d5eff72ca69c1a7");
loginChzzk.isDebug = true;
chat.connectFromChannelId("bb382c2c0cc9fa7c86ab3b037fb5799c");
chat.addListener(new ChatEventListener() {
@Override
public void onConnect() {
System.out.println("Connect received!");
chat.sendChat("ㅋㅋㅋㅋ");
//chat.sendChat("ㅋㅋㅋㅋ");
chat.requestRecentChat(50);
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/ChzzkTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ public ChzzkTestBase() {
currentUserId = properties.getProperty("CURRENT_USER_ID");
chzzk = new ChzzkBuilder().build();
loginChzzk = new ChzzkBuilder(properties.getProperty("NID_AUT"), properties.getProperty("NID_SES")).build();

chzzk.isDebug = true;
loginChzzk.isDebug = true;
}
}

0 comments on commit 826d782

Please sign in to comment.