示例#1
0
func mkPlaylist(dir string, m []*Media) string {
	defer func() {
		if r := recover(); r != nil {
			Logger.Critical("%v %v", "Recovered in mkPlaylist", r)
		}
	}()
	token := strings.Split(m[0].T, "/")
	var t *template.Template
	if token[0] == "audio" {
		t = template.New("audio.tmpl")
	} else if token[0] == "video" {
		t = template.New("video.tmpl")
	}
	t = template.Must(t.ParseGlob(*tmpldir))
	var buf bytes.Buffer
	var ms Medias
	ms.Title = dir2title(dir)
	ms.Ms = m
	err := t.Execute(&buf, ms)
	if err != nil {
		Logger.Error("%v", err.Error())
	}
	return buf.String()
}