-
Notifications
You must be signed in to change notification settings - Fork 19
/
player.go
81 lines (64 loc) · 1.37 KB
/
player.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
package go_librespot
import (
"errors"
metadatapb "github.com/devgianlu/go-librespot/proto/spotify/metadata"
)
var (
ErrMediaRestricted = errors.New("media is restricted")
ErrNoSupportedFormats = errors.New("no supported formats")
)
type Media struct {
track *metadatapb.Track
episode *metadatapb.Episode
}
func NewMediaFromTrack(track *metadatapb.Track) *Media {
if track == nil {
panic("nil track")
}
return &Media{track: track, episode: nil}
}
func NewMediaFromEpisode(episode *metadatapb.Episode) *Media {
if episode == nil {
panic("nil episode")
}
return &Media{track: nil, episode: episode}
}
func (te Media) IsTrack() bool {
return te.track != nil
}
func (te Media) IsEpisode() bool {
return te.episode != nil
}
func (te Media) Track() *metadatapb.Track {
if te.track == nil {
panic("not a track")
}
return te.track
}
func (te Media) Episode() *metadatapb.Episode {
if te.episode == nil {
panic("not an episode")
}
return te.episode
}
func (te Media) Name() string {
if te.track != nil {
return *te.track.Name
} else {
return *te.episode.Name
}
}
func (te Media) Duration() int32 {
if te.track != nil {
return *te.track.Duration
} else {
return *te.episode.Duration
}
}
func (te Media) Restriction() []*metadatapb.Restriction {
if te.track != nil {
return te.track.Restriction
} else {
return te.episode.Restriction
}
}