Skip to content

Commit

Permalink
stream info(getStreamInfo fun) add
Browse files Browse the repository at this point in the history
  • Loading branch information
dalbodeule committed Jun 16, 2024
1 parent c22c703 commit 09bb485
Showing 1 changed file with 69 additions and 5 deletions.
74 changes: 69 additions & 5 deletions src/main/kotlin/space/mori/chzzk_bot/chzzk/ChzzkApis.kt
Original file line number Diff line number Diff line change
@@ -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<T>(
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 = "",
Expand Down Expand Up @@ -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<String> = 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<Any> = 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<IFollowContent> {
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)
Expand All @@ -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<IData<IFollowContent>>() {})

return follow
} catch(e: Exception) {
throw e
}
}
}

fun getStreamInfo(userId: String) : IData<IStreamInfo> {
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<IData<IStreamInfo>>() {})

return follow
} catch(e: Exception) {
throw e
}
}
}
}

0 comments on commit 09bb485

Please sign in to comment.