/
stream_description.go
76 lines (63 loc) · 1.66 KB
/
stream_description.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
package broadcast
import (
"strconv"
)
type StreamDescription struct {
BitRate int
Public bool
Name string
Description string
URL string
Genre string
}
func (description *StreamDescription) IsEmpty() bool {
return description.BitRate == 0 && description.Name == "" && description.Description == "" && description.URL == "" && description.Genre == ""
}
func (description *StreamDescription) IcecastHeaders() map[string]string {
headers := map[string]string{}
headers["ice-public"] = description.PublicZeroOrOne()
if description.BitRate > 0 {
headers["ice-bitrate"] = strconv.Itoa(description.BitRate)
}
var stringAttributes = []struct {
name string
value string
}{
{"ice-name", description.Name},
{"ice-url", description.URL},
{"ice-genre", description.Genre},
{"ice-description", description.Description},
}
for _, attribute := range stringAttributes {
if attribute.value != "" {
headers[attribute.name] = attribute.value
}
}
return headers
}
func (description *StreamDescription) ShoutcastHeaders() map[string]string {
headers := map[string]string{}
headers["icy-pub"] = description.PublicZeroOrOne()
headers["icy-br"] = strconv.Itoa(description.BitRate / 1000)
var stringAttributes = []struct {
name string
value string
}{
{"icy-name", description.Name},
{"icy-url", description.URL},
{"icy-genre", description.Genre},
}
for _, attribute := range stringAttributes {
if attribute.value != "" {
headers[attribute.name] = attribute.value
}
}
return headers
}
func (description *StreamDescription) PublicZeroOrOne() string {
if description.Public {
return "1"
} else {
return "0"
}
}