mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-09 15:28:21 +00:00
stream info(getStreamInfo fun) add
This commit is contained in:
parent
c22c70398f
commit
09bb485a13
@ -1,16 +1,18 @@
|
|||||||
package space.mori.chzzk_bot.chzzk
|
package space.mori.chzzk_bot.chzzk
|
||||||
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.reflect.TypeToken
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
data class IFollow(
|
data class IData<T>(
|
||||||
val code: Int = 200,
|
val code: Int = 200,
|
||||||
val message: String? = null,
|
val message: String? = null,
|
||||||
val content: IFollowContent = IFollowContent()
|
val content: T
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Follows
|
||||||
data class IFollowContent(
|
data class IFollowContent(
|
||||||
val userIdHash: String = "",
|
val userIdHash: String = "",
|
||||||
val nickname: String = "",
|
val nickname: String = "",
|
||||||
@ -45,10 +47,53 @@ data class NicknameColor(
|
|||||||
val colorCode: String = ""
|
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 client = OkHttpClient()
|
||||||
val gson = Gson()
|
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 url = "https://comm-api.game.naver.com/nng_main/v1/chats/$chatID/users/$userId/profile-card?chatType=STREAMING"
|
||||||
val request = Request.Builder()
|
val request = Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
@ -58,7 +103,26 @@ fun getFollowDate(chatID: String, userId: String) : IFollow {
|
|||||||
try {
|
try {
|
||||||
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
|
if(!response.isSuccessful) throw IOException("Unexpected code ${response.code}")
|
||||||
val body = response.body?.string()
|
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
|
return follow
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user