-
Notifications
You must be signed in to change notification settings - Fork 0
/
shout.go
64 lines (51 loc) · 1.13 KB
/
shout.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
package main
import (
"fmt"
"log"
"os"
"io"
"github.com/systemfreund/go-libshout"
)
var s shout.Shout
var stream chan <- []byte
func setupShout() {
fmt.Printf("Connecting to %s:%d\n",*Hostname, *Port)
// Setup libshout parameters
s = shout.Shout{
Host: *Hostname,
Port: *Port,
User: *Username,
Password: *Password,
Mount: *Mount,
Format: shout.FORMAT_MP3,
Protocol: shout.PROTOCOL_HTTP,
}
// Create a channel where we can send the data
var err error
stream, err = s.Open()
if err != nil {
log.Fatal("Error opening server " + *Hostname + " : " + err.Error())
}
}
func shoutSong( sr SongRecord, buffer []byte ) {
fd,err := os.Open(sr.fullpath)
if err != nil {
log.Println("Problems opening " + sr.fullpath + " : " + err.Error())
return
}
// add track info to the stream
track := sr.title + " by " + sr.artist
fmt.Println("Playing " + track)
s.UpdateMetadata( "song", track )
for {
// Read from file
n, err := fd.Read(buffer)
if err != nil && err != io.EOF { panic(err) }
if n == 0 { break }
// Send to shoutcast server
stream <- buffer
}
}
func closeShout() {
s.Close()
}