diff --git a/README.md b/README.md index c562c8a..d448c52 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build.gradle.kts b/build.gradle.kts index 3000f4f..f65b1dd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "io.github.R2turnTrue" -version = "0.0.1" +version = "0.0.2" val publishProps = Properties() publishProps.load( @@ -50,7 +50,7 @@ publishing { artifactId = "chzzk4j" groupId = "io.github.R2turnTrue" - version = "0.0.1" + version = "0.0.2" from(components["java"]) diff --git a/src/main/java/xyz/r2turntrue/chzzk4j/Chzzk.java b/src/main/java/xyz/r2turntrue/chzzk4j/Chzzk.java index 9babe93..d83f155 100644 --- a/src/main/java/xyz/r2turntrue/chzzk4j/Chzzk.java +++ b/src/main/java/xyz/r2turntrue/chzzk4j/Chzzk.java @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/src/main/java/xyz/r2turntrue/chzzk4j/chat/ChzzkChat.java b/src/main/java/xyz/r2turntrue/chzzk4j/chat/ChzzkChat.java index e48d17f..c2ce3cd 100644 --- a/src/main/java/xyz/r2turntrue/chzzk4j/chat/ChzzkChat.java +++ b/src/main/java/xyz/r2turntrue/chzzk4j/chat/ChzzkChat.java @@ -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(); @@ -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; diff --git a/src/main/java/xyz/r2turntrue/chzzk4j/util/RawApiUtils.java b/src/main/java/xyz/r2turntrue/chzzk4j/util/RawApiUtils.java index ca4408e..aa5fc97 100644 --- a/src/main/java/xyz/r2turntrue/chzzk4j/util/RawApiUtils.java +++ b/src/main/java/xyz/r2turntrue/chzzk4j/util/RawApiUtils.java @@ -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"); } } diff --git a/src/test/java/ChatTest.java b/src/test/java/ChatTest.java index 5110aa1..eb41f06 100644 --- a/src/test/java/ChatTest.java +++ b/src/test/java/ChatTest.java @@ -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); } diff --git a/src/test/java/ChzzkTestBase.java b/src/test/java/ChzzkTestBase.java index 76741e6..b7ea092 100644 --- a/src/test/java/ChzzkTestBase.java +++ b/src/test/java/ChzzkTestBase.java @@ -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; } }