func main() { log.SetFlags(0) usage := `Usage: grooved [options] Options: -c <file>, --config <file> Configuration file [default: ~/.config/grooved/config.ini]. --list-outputs List supported outputs. -V, --verbose Enable verbose log messages [default: false]. -h, --help Show the program's help message and exit.` args, err := docopt.Parse(usage, nil, true, "", false) if err != nil { log.Fatalf("Invalid arguments: %s", err) } cfg_file, err := util.ExpandUser(args["--config"].(string)) if err != nil { log.Fatalf("Error expanding home directory: %s", err) } cfg, err := ini.LoadFile(cfg_file) if err != nil { log.Fatalf("Error loading config file: %s", err) } player, err := player.Init(cfg) if err != nil { log.Fatalf("Error creating player: %s", err) } if args["--list-outputs"].(bool) { outputs, err := player.GetOutputList() if err != nil { log.Fatalf("Error retrieving property: %s", err) } sort.Strings(outputs) for _, output := range outputs { log.Println(output) } os.Exit(0) } if args["--verbose"].(bool) { player.Verbose = true } err = bus.Run(player) if err != nil { log.Fatalf("Error creating dbus service: %s", err) } err = player.Run() if err != nil { log.Fatalf("Error running player: %s", err) } player.Wait.Wait() }
func Init(cfg ini.File) (*Player, error) { p := &Player{ Status: StatusStopped, started: false, } p.handle = C.mpv_create() if p.handle == nil { return nil, fmt.Errorf("Could not create player") } err := p.SetOptionString("audio-client-name", "grooved") if err != nil { return nil, fmt.Errorf("Could not set option 'audio-client-name': %s", err) } err = p.SetOptionString("title", "${?media-title:${media-title}}${!media-title:No file.}") if err != nil { return nil, fmt.Errorf("Could not set option 'title': %s", err) } err = p.SetOptionString("no-config", "") if err != nil { return nil, fmt.Errorf("Could not set option 'no-config': %s", err) } err = p.SetOptionString("no-video", "") if err != nil { return nil, fmt.Errorf("Could not set option 'no-video': %s", err) } err = p.SetOptionString("no-sub", "") if err != nil { return nil, fmt.Errorf("Could not set option 'no-sub': %s", err) } err = p.SetOptionString("no-softvol", "") if err != nil { return nil, fmt.Errorf("Could not set option 'no-softvol': %s", err) } if cfg["default"]["cache"] != "" { p.SetOptionString("cache", cfg["default"]["cache"]) } if cfg["default"]["gapless"] != "" { p.SetOptionString("gapless-audio", cfg["default"]["gapless"]) } p.library, _ = util.ExpandUser(cfg["default"]["library"]) if cfg["default"]["notify"] == "yes" { p.notify = true } else { p.notify = false } if cfg["default"]["replaygain"] != "" { rgain_af := fmt.Sprintf("volume=replaygain-%s", cfg["default"]["replaygain"]) if cfg["default"]["filters"] != "" { cfg["default"]["filters"] += "," + rgain_af } else { cfg["default"]["filters"] = rgain_af } } if cfg["default"]["output"] != "" { p.SetOptionString("ao", cfg["default"]["output"]) } if cfg["default"]["ytdl"] != "" { p.SetOptionString("ytdl", cfg["default"]["ytdl"]) } if cfg["default"]["verbose"] != "" { p.Verbose = true } if cfg["default"]["filters"] != "" { p.SetOptionString("af", cfg["default"]["filters"]) } if cfg["default"]["scripts"] != "" { p.SetOptionString("lua", cfg["default"]["scripts"]) } C.mpv_request_log_messages(p.handle, C.CString("warn")) mp_err := C.mpv_initialize(p.handle) if mp_err != 0 { return nil, ErrorString(mp_err) } return p, nil }