forked from dweymouth/go-jellyfin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.go
83 lines (73 loc) · 1.78 KB
/
misc.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
package jellyfin
import (
"fmt"
"io"
)
type setFavoriteBody struct{}
func (c *Client) SetFavorite(id string, favorite bool) error {
endpoint := fmt.Sprintf("/Users/%s/FavoriteItems/%s", c.userID, id)
var resp io.ReadCloser
var err error
if favorite {
resp, err = c.post(endpoint, c.defaultParams(), setFavoriteBody{})
} else {
resp, err = c.delete(endpoint, c.defaultParams())
}
if err != nil {
return err
}
resp.Close()
return nil
}
type refreshLibraryBody struct{}
func (c *Client) RefreshLibrary() error {
resp, err := c.post("/Library/Refresh", c.defaultParams(), refreshLibraryBody{})
if err != nil {
return err
}
resp.Close()
return nil
}
type PlayEvent string
const (
Start PlayEvent = "start"
Stop PlayEvent = "stop"
Pause PlayEvent = "pause"
Unpause PlayEvent = "unpause"
TimeUpdate PlayEvent = "timeupdate"
)
type playStatusBody struct {
ItemId string `json:"ItemId"`
PositionTicks int64 `json:"PositionTicks"`
EventName string `json:"EventName,omitempty"`
IsPaused *bool `json:"IsPaused,omitempty"`
}
func (c *Client) UpdatePlayStatus(songID string, event PlayEvent, positionTicks int64) error {
body := playStatusBody{ItemId: songID, PositionTicks: positionTicks}
path := "/Sessions/Playing/Progress"
isPaused := new(bool)
switch event {
case Start:
path = "/Sessions/Playing"
case Stop:
path = "/Sessions/Playing/Stopped"
*isPaused = true
body.IsPaused = isPaused
case Pause:
*isPaused = true
body.IsPaused = isPaused
body.EventName = string(event)
case Unpause:
*isPaused = false
body.IsPaused = isPaused
body.EventName = string(event)
case TimeUpdate:
body.EventName = string(event)
}
resp, err := c.post(path, c.defaultParams(), body)
if err != nil {
return err
}
resp.Close()
return nil
}