-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_status.go
234 lines (201 loc) · 6.92 KB
/
player_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package nico
import (
"context"
"encoding/xml"
"errors"
"net/http"
"net/url"
)
// PlayerStatus is niconico live player status.
type PlayerStatus struct {
Status string `xml:"status,attr"`
Time int64 `xml:"time,attr"`
Stream Stream `xml:"stream"`
User User `xml:"user"`
Rtmp Rtmp `xml:"rtmp"`
Ms Ms `xml:"ms"`
// TODO
TidList interface{} `xml:"tid_list"`
Twitter Twitter `xml:"twitter"`
Player Player `xml:"player"`
Marquee Marquee `xml:"marquee"`
Error Error `xml:"error"`
}
// Stream is niconico live player status in player status.
type Stream struct {
ID string `xml:"id"`
Title string `xml:"title"`
Description string `xml:"description"`
ProviderType string `xml:"provider_type"`
DefaultCommunity string `xml:"default_community"`
International int64 `xml:"international"`
IsOwner int64 `xml:"is_owner"`
OwnerID int64 `xml:"owner_id"`
OwnerName string `xml:"owner_name"`
IsReserved int64 `xml:"is_reserved"`
IsNiconicoEnqueteEnabled int64 `xml:"is_niconico_enquete_enabled"`
WatchCount int64 `xml:"watch_count"`
CommentCount int64 `xml:"comment_count"`
BaseTime int64 `xml:"base_time"`
OpenTime int64 `xml:"open_time"`
StartTime int64 `xml:"start_time"`
EndTime int64 `xml:"end_time"`
IsRerunStream int64 `xml:"is_rerun_stream"`
// TODO
BourbonURL interface{} `xml:"bourbon_url"`
FullVideo interface{} `xml:"full_video"`
AfterVideo interface{} `xml:"after_video"`
BeforeVideo interface{} `xml:"before_video"`
KickoutVideo interface{} `xml:"kickout_video"`
TwitterTag string `xml:"twitter_tag"`
DanjoCommentMode int64 `xml:"danjo_comment_mode"`
InfinityMode int64 `xml:"infinity_mode"`
Archive int64 `xml:"archive"`
Press Press `xml:"press"`
// TODO
PluginDelay interface{} `xml:"plugin_delay"`
PluginURL interface{} `xml:"plugin_url"`
PluginURLs interface{} `xml:"plugin_urls"`
AllowNetduetto int64 `xml:"allow_netduetto"`
NgScoring int64 `xml:"ng_scoring"`
IsNonarchiveTimeshiftEnabled int64 `xml:"is_nonarchive_timeshift_enabled"`
IsTimeshiftReserved int64 `xml:"is_timeshift_reserved"`
HeaderComment int64 `xml:"header_comment"`
FooterComment int64 `xml:"footer_comment"`
SplitBottom int64 `xml:"split_bottom"`
SplitTop int64 `xml:"split_top"`
BackgroundComment int64 `xml:"background_comment"`
// TODO
FontScale interface{} `xml:"font_scale"`
CommentLock int64 `xml:"comment_lock"`
Telop Telop `xml:"telop"`
ContentsList ContentsList `xml:"contents_list"`
PictureURL string `xml:"picture_url"`
ThumbURL string `xml:"thumb_url"`
// TODO
IsPriorityPrefecture interface{} `xml:"is_priority_prefecture"`
}
// Press is unknown data.
type Press struct {
DisplayLines int64 `xml:"display_lines"`
DisplayTime int64 `xml:"display_time"`
// TODO
StyleConf interface{} `xml:"style_conf"`
}
// Telop is unknown data.
type Telop struct {
Enable int64 `xml:"enable"`
}
// ContentsList is a list of contents.
type ContentsList struct {
// TODO slice?
Contents Contents `xml:"contents"`
}
// Contents is detailed information of contents such as URL of RTMP etc.
type Contents struct {
ID string `xml:"id,attr"`
DisableAudio int64 `xml:"disableAudio,attr"`
DisableVideo int64 `xml:"disableVideo,attr"`
StartTime int64 `xml:"start_time,attr"`
Contents string `xml:",chardata"`
}
// User is niconico user data in player status.
type User struct {
UserID int64 `xml:"user_id"`
Nickname string `xml:"nickname"`
IsPremium int64 `xml:"is_premium"`
UserAge int64 `xml:"userAge"`
UserSex int64 `xml:"userSex"`
UserDomain string `xml:"userDomain"`
UserPrefecture int64 `xml:"userPrefecture"`
UserLanguage string `xml:"userLanguage"`
RoomLabel string `xml:"room_label"`
RoomSeetno int64 `xml:"room_seetno"`
// TODO
IsJoin interface{} `xml:"is_join"`
TwitterInfo TwitterInfo `xml:"twitter_info"`
}
// TwitterInfo is user's twitter info in user.
type TwitterInfo struct {
Status string `xml:"status"`
ScreenName interface{} `xml:"screen_name"`
FollowersCount int64 `xml:"followers_count"`
IsVip int64 `xml:"is_vip"`
ProfileImageURL string `xml:"profile_image_url"`
AfterAuth int64 `xml:"after_auth"`
TweetToken string `xml:"tweet_token"`
}
// Rtmp is information on RTMP.
type Rtmp struct {
IsFms int64 `xml:"is_fms,attr"`
RtmptPort int64 `xml:"rtmpt_port,attr"`
URL string `xml:"url"`
Ticket string `xml:"ticket"`
}
// Ms is comment server information.
type Ms struct {
Addr string `xml:"addr"`
Port int64 `xml:"port"`
Thread int64 `xml:"thread"`
}
// Twitter is Twitter setting information of the niconico live.
type Twitter struct {
LiveEnabled int64 `xml:"live_enabled"`
VipModeCount int64 `xml:"vip_mode_count"`
LiveAPIURL string `xml:"live_api_url"`
}
// Player is the setting information of the player.
type Player struct {
QosAnalytics int64 `xml:"qos_analytics"`
DialogImage DialogImage `xml:"dialog_image"`
IsNoticeViewerBalloonEnabled int64 `xml:"is_notice_viewer_balloon_enabled"`
ErrorReport int64 `xml:"error_report"`
}
// DialogImage is the URL of the dialog image displayed to the player.
type DialogImage struct {
Oidashi string `xml:"oidashi"`
}
// Marquee is information related to the game etc.
type Marquee struct {
Category string `xml:"category"`
GameKey string `xml:"game_key"`
GameTime int64 `xml:"game_time"`
ForceNicowariOff int64 `xml:"force_nicowari_off"`
}
// Error stores the error code if Status of PlayerStatus is not ok.
type Error struct {
Code string `xml:"code"`
}
// GetPlayerStatus gets the player status.
func (c *Client) GetPlayerStatus(ctx context.Context, liveID string) (*PlayerStatus, error) {
u, err := url.Parse(c.liveBaseRawurl)
if err != nil {
return nil, err
}
u.Path = "api/getplayerstatus"
v := url.Values{}
v.Set("v", liveID)
u.RawQuery = v.Encode()
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
req.AddCookie(&http.Cookie{Name: "user_session", Value: c.UserSession})
resp, err := c.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.New(resp.Status)
}
ps := PlayerStatus{}
if err := xml.NewDecoder(resp.Body).Decode(&ps); err != nil {
return nil, err
}
if ps.Status != "ok" {
return nil, PlayerStatusError{Status: ps.Status, Code: ps.Error.Code}
}
return &ps, nil
}