stream info(getStreamInfo fun) add

This commit is contained in:
dalbodeule 2024-06-16 22:07:15 +09:00
parent c22c70398f
commit 09bb485a13
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65

View File

@ -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 = "",
@ -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)
@ -58,7 +103,26 @@ 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) {