forked from CedArctic/go-vlc-ctrl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylist.go
More file actions
39 lines (35 loc) · 1.25 KB
/
playlist.go
File metadata and controls
39 lines (35 loc) · 1.25 KB
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
package vlcctrl
import "encoding/json"
// Node structure (node or leaf type) is the basic element of VLC's playlist tree representation.
// Leafs are playlist items. Nodes are playlists or folders inside playlists.
type Node struct {
Ro string `json:"ro"`
Type string `json:"type"` // node or leaf
Name string `json:"name"`
ID string `json:"id"`
Duration int `json:"duration,omitempty"`
URI string `json:"uri,omitempty"`
Current string `json:"current,omitempty"`
Children []Node `json:"children,omitempty"`
}
// ParsePlaylist parses Playlist() responses to Node
func ParsePlaylist(playlistResponse string) (playlist Node, err error) {
err = json.Unmarshal([]byte(playlistResponse), &playlist)
if err != nil {
return
}
return
}
// Playlist returns a Node object that is the root node of VLC's Playlist tree
// Playlist tree structure: Level 0 - Root Node (Type="node"), Level 1 - Playlists (Type="node"),
// Level 2+: Playlist Items (Type="leaf") or Folder (Type="node")
func (instance *VLC) Playlist() (playlist Node, err error) {
// Make response and check for errors
response, err := instance.RequestMaker("/requests/playlist.json")
if err != nil {
return
}
// Parse to node
playlist, err = ParsePlaylist(response)
return
}