From 09bb485a136bc1b7a1c9b37308bab7b7978e0c13 Mon Sep 17 00:00:00 2001 From: dalbodeule <11470513+dalbodeule@users.noreply.github.com> Date: Sun, 16 Jun 2024 22:07:15 +0900 Subject: [PATCH] stream info(getStreamInfo fun) add --- .../space/mori/chzzk_bot/chzzk/ChzzkApis.kt | 74 +++++++++++++++++-- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt b/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt index 479b89e..150bde9 100644 --- a/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt +++ b/src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt @@ -1,16 +1,18 @@ package space.mori.chzzk_bot.chzzk import com.google.gson.Gson +import com.google.gson.reflect.TypeToken import okhttp3.OkHttpClient import okhttp3.Request import java.io.IOException -data class IFollow( +data class IData( val code: Int = 200, val message: String? = null, - val content: IFollowContent = IFollowContent() + val content: T ) +// Follows data class IFollowContent( val userIdHash: String = "", val nickname: String = "", @@ -45,10 +47,53 @@ data class NicknameColor( val colorCode: String = "" ) +// Stream info +data class IStreamInfo( + val liveId: Int = 0, + val liveTitle: String = "", + val status: String = "", + val liveImageUrl: String = "", + val defaultThumbnailImageUrl: String? = null, + val concurrentUserCount: Int = 0, + val accumulateCount: Int = 0, + val openDate: String = "", + val closeDate: String = "", + val adult: Boolean = false, + val clipActive: Boolean = false, + val tags: List = emptyList(), + val chatChannelId: String = "", + val categoryType: String = "", + val liveCategory: String = "", + val liveCategoryValue: String = "", + val chatActive: Boolean = true, + val chatAvailableGroup: String = "", + val paidPromotion: Boolean = false, + val chatAvailableCondition: String = "", + val minFollowerMinute: Int = 0, + val livePlaybackJson: String = "", + val p2pQuality: List = emptyList(), + val channel: Channel = Channel(), + val livePollingStatusJson: String = "", + val userAdultStatus: String? = null, + val chatDonationRankingExposure: Boolean = true, + val adParameter: AdParameter = AdParameter() +) + +data class Channel( + val channelId: String = "", + val channelName: String = "", + val channelImageUrl: String = "", + val verifiedMark: Boolean = false +) + +data class AdParameter( + val tag: String = "" +) + val client = OkHttpClient() val gson = Gson() -fun getFollowDate(chatID: String, userId: String) : IFollow { +fun getFollowDate(chatID: String, userId: String) : IData { val url = "https://comm-api.game.naver.com/nng_main/v1/chats/$chatID/users/$userId/profile-card?chatType=STREAMING" val request = Request.Builder() .url(url) @@ -58,11 +103,30 @@ fun getFollowDate(chatID: String, userId: String) : IFollow { try { if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}") val body = response.body?.string() - val follow = gson.fromJson(body, IFollow::class.java) + val follow = gson.fromJson(body, object: TypeToken>() {}) + + return follow + } catch(e: Exception) { + throw e + } + } +} + +fun getStreamInfo(userId: String) : IData { + val url = "https://api.chzzk.naver.com/service/v2/channels/${userId}/live-detail" + val request = Request.Builder() + .url(url) + .build() + + client.newCall(request).execute().use { response -> + try { + if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}") + val body = response.body?.string() + val follow = gson.fromJson(body, object: TypeToken>() {}) return follow } catch(e: Exception) { throw e } } -} \ No newline at end of file +}