Skip to content

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

License

Notifications You must be signed in to change notification settings

R2turnTrue/chzzk4j

Repository files navigation

chzzk4j

/ Example Minecraft Plugin / Discord Server

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

  • This library is not completed. Please contribute a lot through Pull-Request!
  • Please feel free to create an issue if you have any problems!

installation

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.R2turnTrue:chzzk4j:0.0.12")
}

examples

initializing

// Debug Mode (Enables debug logs of System.out)
Chzzk chzzk = new ChzzkBuilder()
        .withDebugMode()
        .build();

// Unauthorized CHZZK (Anonymous)
Chzzk chzzk = new ChzzkBuilder().build();

// You can get values of NID_AUT and NID_SES from developer tools of your browser.
// In Chrome, you can see the values from
// Application > Cookies > https://chzzk.naver.com

// Authorized CHZZK
Chzzk chzzk = new ChzzkBuilder()
                .withAuthorization(NID_AUT, NID_SES)
                .build();

get information of logged-in user

get channel information

String CHANNEL_ID = "7ce8032370ac5121dcabce7bad375ced";
ChzzkChannel channel = chzzk.getChannel("CHANNEL_ID");

// Print nickname of channel
System.out.println(channel.getChannelName());

ChzzkChannelRules rules = channel.getRules(chzzk);
// or
ChzzkChannelRules rules = chzzk.getChannelChatRules("7ce8032370ac5121dcabce7bad375ced");

System.out.println(rules.getRule());

connecting to chats (read)

ChzzkChat chat = chzzk.chat("7f148028d1b8b3feab3a5442badded46")
        .withChatListener(new ChatEventListener() {
            @Override
            public void onConnect(ChzzkChat chat, boolean isReconnecting) {
                System.out.println("Connect received!");

                // !! when re-connecting, you shouldn't need to request recent chats!
                if (!isReconnecting)
                    chat.requestRecentChat(50);
            }

            @Override
            public void onError(Exception ex) {
                ex.printStackTrace();
            }

            @Override
            public void onChat(ChatMessage msg) {

                System.out.println(msg);

                if (msg.getProfile() == null) {
                    System.out.println("[Chat] 익명: " + msg.getContent());
                    return;
                }

                System.out.println("[Chat] " + msg.getProfile().getNickname() + ": " + msg.getContent());
            }

            @Override
            public void onDonationChat(DonationMessage msg) {
                if (msg.getProfile() == null) {
                    System.out.println("[Donation] 익명: " + msg.getContent() + ": " + msg.getContent() + " [" + msg.getPayAmount() + "원]");
                    return;
                }

                System.out.println("[Donation] " + msg.getProfile().getNickname() + ": " + msg.getContent() + " [" + msg.getPayAmount() + "원]");
            }

            @Override
            public void onSubscriptionChat(SubscriptionMessage msg) {
                if (msg.getProfile() == null) {
                    System.out.println("[Subscription] 익명: " + msg.getContent() + ": [" + msg.getSubscriptionMonth() + "개월 " + msg.getSubscriptionTierName() + "]");
                    return;
                }

                System.out.println("[Subscription] " + msg.getProfile().getNickname() + ": [" + msg.getSubscriptionMonth() + "개월 " + msg.getSubscriptionTierName() + "]");
            }

            @Override
            public void onMissionDonationChat(MissionDonationMessage msg) {
                if (msg.getProfile() == null) {
                    System.out.println("[Mission] 익명: " + msg.getMissionText() + ": [" + msg.getPayAmount() + "원]");
                    return;
                }

                System.out.println("[Mission] 익명: " + msg.getMissionText() + ": [" + msg.getPayAmount() + "원]");
            }
        })
        .build();

chat.connectBlocking();
Thread.sleep(700000);
chat.closeBlocking();

connecting to chats (send)

Chzzk chzzk = new ChzzkBuilder()
        .withAuthorization(NID_AUT, NID_SES)
        .build();

ChzzkChat chat = chzzk.chat("7f148028d1b8b3feab3a5442badded46")
        .withChatListener(new ChatEventListener() {
            @Override
            public void onConnect(ChzzkChat chat, boolean isReconnecting) {
                System.out.println("Connect received!");
                chat.sendChat("안녕하세요!");
            }
        })
        .build();

chat.connectBlocking();
Thread.sleep(700000);
chat.closeBlocking();

get live details/status

chzzk.getLiveStatus("Channel ID");
chzzk.getLiveDetail("Channel ID");

Naver Login

Naver login requires Selenium and ChromeDriver configuration.

  1. Click here to move ChromeDriver download page.
  2. Add ChromeDriver path to system property
void doSomething() {
    Chrome.setDriverProperty("Your ChromeDriver path");
}
void authorizeChzzkAutomatically() {
    Naver naver = new Naver("Naver ID", "Naver Password");
    naver.login().thenRun(() -> {
        Chzzk chzzk = new ChzzkBuilder()
                .withAuthorization(naver)
                .build();

        System.out.println(chzzk.getLoggedUser());
    }).join();
}

features

  • get channel information & rules
  • get current user's information
  • get channel followed status
  • async chat integration (read/send)
  • get recommendation channels
  • fix invalid json (chat)
  • load emoji pack
  • get live status
  • get live detail

need to implement

  • write javadocs of all methods/classes/etc..
  • parse emoji from chat message
  • get following channels of user that logged in
  • get video information
  • get cheese ranking

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages