Permalink
Browse files

pls generation

  • Loading branch information...
1 parent e87aae2 commit bc4b241a31982db9f3891d2e744ddf1a8c781783 @adg adg committed Oct 21, 2011
Showing with 34 additions and 9 deletions.
  1. +18 −9 icecloud.go
  2. +16 −0 template.go
View
@@ -13,6 +13,7 @@ import (
"log"
"os"
"time"
+ "template"
)
type Config struct {
@@ -275,29 +276,37 @@ func (c *Config) sshCommand(s *Server, command string, stdin io.Reader) os.Error
func (c *Config) Playlist(mount []string) os.Error {
for _, m := range mount {
- if err := c.writePlaylist(m); err != nil {
+ if err := c.writePlaylist(m, "m3u", m3uTmpl); err != nil {
+ return err
+ }
+ if err := c.writePlaylist(m, "pls", plsTmpl); err != nil {
return err
}
}
return nil
}
-func (c *Config) writePlaylist(mount string) os.Error {
+func (c *Config) writePlaylist(mount, ext string, t *template.Template) os.Error {
for i, s := range c.Server {
if s.Kind == "master" {
continue
}
- fn := fmt.Sprintf("%s-%s.m3u", mount, s.Name)
- f, err := os.Create(fn)
- if err != nil {
- return err
- }
- fmt.Fprintf(f, "%s%s\n", c.ServerURL(s), mount)
+ url := fmt.Sprintf("%s%s", c.ServerURL(s), mount)
+ servers := []string{url}
for j, s := range c.Server {
if s.Kind == "master" || i == j {
continue
}
- fmt.Fprintf(f, "%s%s\n", c.ServerURL(s), mount)
+ url := fmt.Sprintf("%s%s", c.ServerURL(s), mount)
+ servers = append(servers, url)
+ }
+ name := fmt.Sprintf("%s-%s.%s", mount, s.Name, ext)
+ f, err := os.Create(name)
+ if err != nil {
+ return err
+ }
+ if err := t.Execute(f, servers); err != nil {
+ return err
}
f.Close()
}
View
@@ -118,3 +118,19 @@ sudo chmod 660 /etc/icecast2/icecast.xml
sudo /etc/init.d/icecast2 restart
`
+
+var m3uTmpl = template.Must(template.New("m3u").Parse(
+ "{{range .}}{{.}}\n{{end}}"))
+
+var plsTmpl = template.Must(template.New("m3u").Funcs(template.FuncMap{
+ "idx": func(i int) int { return i + 1 },
+}).Parse(`
+[playlist]
+{{range $i, $s := .}}
+File{{idx $i}}={{$s}}
+Title{{idx $i}}=Server {{idx $i}}
+Length{{idx $i}}=-1
+{{end}}
+NumberOfEntries={{len .}}
+Version=2
+`))

0 comments on commit bc4b241

Please sign in to comment.