-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.go
51 lines (44 loc) · 1.05 KB
/
item.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
package piplayer
import (
"os"
"path/filepath"
)
// Item represents a playlist item
// it can have a visual element, an audio element, or both.
// more elements such as timers can be added later.
type Item struct {
Audio os.FileInfo
Visual os.FileInfo
Type string
Cues map[string]string
}
// ItemString is a simpler representation of an Item,
// where only the file name for the Audio and Visual elements are stored.
type ItemString struct {
Audio string
Visual string
Type string
Cues map[string]string
}
// Name returns the filename of the visual element.
func (i *Item) Name() string {
return removeExtension(i.Visual.Name())
}
// String returns an newly created ItemString version of the Item.
func (i *Item) String() ItemString {
is := ItemString{}
if i.Audio != nil {
is.Audio = i.Audio.Name()
}
if i.Visual != nil {
is.Visual = i.Visual.Name()
}
is.Type = i.Type
is.Cues = i.Cues
return is
}
func removeExtension(filename string) string {
ext := filepath.Ext(filename)
l := len(filename) - len(ext)
return filename[:l]
}