diff options
Diffstat (limited to 'types')
-rw-r--r-- | types/live.go | 3 | ||||
-rw-r--r-- | types/live_list.go | 17 | ||||
-rw-r--r-- | types/live_room.go | 141 | ||||
-rw-r--r-- | types/net_type.go | 28 | ||||
-rw-r--r-- | types/types.go | 9 |
5 files changed, 198 insertions, 0 deletions
diff --git a/types/live.go b/types/live.go new file mode 100644 index 0000000..9fe2314 --- /dev/null +++ b/types/live.go @@ -0,0 +1,3 @@ +package types + +type RoomId uint64 diff --git a/types/live_list.go b/types/live_list.go new file mode 100644 index 0000000..8d4e890 --- /dev/null +++ b/types/live_list.go @@ -0,0 +1,17 @@ +package types + +type LiveList struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data struct { + Count int `json:"count"` + Data []struct { + Face string `json:"face"` + Link string `json:"link"` + Roomid RoomId `json:"roomid"` + Roomname string `json:"roomname"` + Nickname string `json:"nickname"` + } `json:"data"` + } `json:"data"` +} diff --git a/types/live_room.go b/types/live_room.go new file mode 100644 index 0000000..6d39ecb --- /dev/null +++ b/types/live_room.go @@ -0,0 +1,141 @@ +package types + +type RoomUrlInfoResponse = BaseResponse[roomUrlInfo] + +type roomUrlInfo struct { + CurrentQuality int `json:"current_quality"` + AcceptQuality []string `json:"accept_quality"` + CurrentQualityNumber int `json:"current_qn"` + QualityDescription []qualityDescription `json:"quality_description"` + URLs []StreamingUrlInfo `json:"durl"` +} + +type qualityDescription struct { + QualityNumber int `json:"qn"` + Description string `json:"desc"` +} + +type StreamingUrlInfo struct { + URL string `json:"url"` + Length int `json:"length"` + Order int `json:"order"` + StreamType int `json:"stream_type"` + P2pType int `json:"p2p_type"` +} + +type roomProfile struct { + UID int `json:"uid"` + RoomID RoomId `json:"room_id"` + ShortID int `json:"short_id"` + Attention int `json:"attention"` + Online int `json:"online"` + IsPortrait bool `json:"is_portrait"` + Description string `json:"description"` + LiveStatus int `json:"live_status"` + AreaID int `json:"area_id"` + ParentAreaID int `json:"parent_area_id"` + ParentAreaName string `json:"parent_area_name"` + OldAreaID int `json:"old_area_id"` + Background string `json:"background"` + Title string `json:"title"` + UserCover string `json:"user_cover"` + Keyframe string `json:"keyframe"` + IsStrictRoom bool `json:"is_strict_room"` + LiveTime string `json:"live_time"` + Tags string `json:"tags"` + IsAnchor int `json:"is_anchor"` + RoomSilentType string `json:"room_silent_type"` + RoomSilentLevel int `json:"room_silent_level"` + RoomSilentSecond int `json:"room_silent_second"` + AreaName string `json:"area_name"` + Pendants string `json:"pendants"` + AreaPendants string `json:"area_pendants"` + HotWords []string `json:"hot_words"` + HotWordsStatus int `json:"hot_words_status"` + Verify string `json:"verify"` + NewPendants struct { + Frame struct { + Name string `json:"name"` + Value string `json:"value"` + Position int `json:"position"` + Desc string `json:"desc"` + Area int `json:"area"` + AreaOld int `json:"area_old"` + BgColor string `json:"bg_color"` + BgPic string `json:"bg_pic"` + UseOldArea bool `json:"use_old_area"` + } `json:"frame"` + Badge struct { + Name string `json:"name"` + Position int `json:"position"` + Value string `json:"value"` + Desc string `json:"desc"` + } `json:"badge"` + MobileFrame struct { + Name string `json:"name"` + Value string `json:"value"` + Position int `json:"position"` + Desc string `json:"desc"` + Area int `json:"area"` + AreaOld int `json:"area_old"` + BgColor string `json:"bg_color"` + BgPic string `json:"bg_pic"` + UseOldArea bool `json:"use_old_area"` + } `json:"mobile_frame"` + MobileBadge interface{} `json:"mobile_badge"` + } `json:"new_pendants"` + UpSession string `json:"up_session"` + PkStatus int `json:"pk_status"` + PkID int `json:"pk_id"` + BattleID int `json:"battle_id"` + AllowChangeAreaTime int `json:"allow_change_area_time"` + AllowUploadCoverTime int `json:"allow_upload_cover_time"` + StudioInfo struct { + Status int `json:"status"` + MasterList []interface{} `json:"master_list"` + } `json:"studio_info"` +} + +type RoomProfileResponse = BaseResponse[roomProfile] + +type LiveStatus int + +const ( + Inactive LiveStatus = 0 + Streaming LiveStatus = 1 + Playback LiveStatus = 2 +) + +var liveStatusStringMap = map[LiveStatus]string{ + Inactive: "inactive", + Streaming: "streaming", + Playback: "inactive (playback)", +} + +type roomPlayInfo struct { + RoomID uint64 `json:"room_id"` + ShortID uint `json:"short_id"` + UID uint `json:"uid"` + IsHidden bool `json:"is_hidden"` + IsLocked bool `json:"is_locked"` + IsPortrait bool `json:"is_portrait"` + LiveStatus LiveStatus `json:"live_status"` // 0: inactive 1: streaming 2: playback + HiddenTill int `json:"hidden_till"` + LockTill int `json:"lock_till"` + Encrypted bool `json:"encrypted"` + PwdVerified bool `json:"pwd_verified"` + LiveTime int `json:"live_time"` + RoomShield int `json:"room_shield"` + AllSpecialTypes []interface{} `json:"all_special_types"` + PlayurlInfo interface{} `json:"playurl_info"` +} + +type RoomPlayInfoResponse = BaseResponse[roomPlayInfo] + +func (s LiveStatus) IsStreaming() bool { + return s == Streaming +} + +func (s LiveStatus) String() string { + return liveStatusStringMap[s] +} diff --git a/types/net_type.go b/types/net_type.go new file mode 100644 index 0000000..ce82288 --- /dev/null +++ b/types/net_type.go @@ -0,0 +1,28 @@ +package types + +import "fmt" + +type IpNetType string + +var ( + IPv6Net IpNetType = "ipv6" + IPv4Net IpNetType = "ipv4" + IP64 IpNetType = "any" +) + +// GetDialNetString returns the string accepted by net.Dialer::DialContext +func (t IpNetType) GetDialNetString() string { + switch t { + case IPv4Net: + return "tcp4" + case IPv6Net: + return "tcp6" + case IP64: + return "tcp" + } + return "" +} + +func (t IpNetType) String() string { + return fmt.Sprintf("%s(%s)", string(t), t.GetDialNetString()) +} diff --git a/types/types.go b/types/types.go new file mode 100644 index 0000000..d1b1b70 --- /dev/null +++ b/types/types.go @@ -0,0 +1,9 @@ +// Package types include common data structures used in multiple packages. +package types + +type BaseResponse[T any] struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data T `json:"data"` +} |