func main() { t0 := time.Now() conf := config.Config{} conf.MusicDir = flag.String("music-dir", "/music", "Music dir") conf.Port = flag.Int("port", 8080, "Pickup port") conf.MpdAddress = flag.String("mpd-address", "localhost:6600", "MPD address") conf.MpdPassword = flag.String("mpd-password", "", "MPD Password") flag.Parse(true) log.Printf("Mpd address: '%s' password: '******'\n", *conf.MpdAddress, *conf.MpdPassword) plyr, err := player.NewMpdPlayer(&conf) if err != nil { log.Fatalln("Failed to initialize mpd player", err) } music, err := plyr.GetCollection() if err != nil { log.Fatalln("Failed to retrieve collection", err) } log.Printf("Player with %d categories initialized in %v\n", len(music.Categories), time.Since(t0)) serve(&conf, &plyr) }
func main() { var action = flag.String("action", "serve", "Action to perform (serve|refresh)") conf := config.Config{} conf.MusicDir = flag.String("music-dir", "/music", "Music dir") conf.Port = flag.Int("port", 8080, "Pickup port") conf.MpdAddress = flag.String("mpd-address", "localhost:6600", "MPD address") conf.MpdPassword = flag.String("mpd-password", "", "MPD Password") var query = flag.String("query", "", "Search query") flag.Parse(true) fmt.Println("Action is:", *action) fmt.Printf("Mpd address: '%s' password: '******'\n", *conf.MpdAddress, *conf.MpdPassword) //collection := loadOrRefresh(*conf.MusicDir) music, err := model.RefreshMpd(&conf) if err != nil { log.Fatalf("Couldn't get files from mpd: \n%s\n", err) } switch *action { case "stats": stats(music.Categories[0]) case "search": search(music, *query) case "serve": serve(&conf, music) case "test-playback": testPlayback(&conf, music) case "refresh": os.Exit(0) default: fmt.Println("Unknown action", *action) } }