func main() { flag.Parse() if itlXML != "" && path != "" || itlXML == "" && path == "" { fmt.Println("must specify either -itlXML or -path, see -help for more details") os.Exit(1) } if out == "" { fmt.Println("must specify -out, see -help for more details") os.Exit(1) } var l index.Library var err error switch { case itlXML != "": l, err = importXML(itlXML) case path != "": l = walk.NewLibrary(path) } if err != nil { fmt.Println(err) os.Exit(1) } err = writeLibrary(index.Convert(l, "TrackID")) if err != nil { fmt.Println(err) os.Exit(1) } }
func readLibrary() (index.Library, error) { var count int check := func(x string) { if x != "" { count++ } } check(itlXML) check(tchLib) check(walkPath) switch { case count == 0: return nil, fmt.Errorf("must specify one library file or a path to build one from (-itlXML, -lib or -path)") case count > 1: return nil, fmt.Errorf("must only specify one library file or a path to build one from (-itlXML, -lib or -path)") } var lib index.Library switch { case tchLib != "": f, err := os.Open(tchLib) if err != nil { return nil, fmt.Errorf("could not open Tchaik library file: %v", err) } defer f.Close() fmt.Printf("Parsing %v...", tchLib) lib, err = index.ReadFrom(f) if err != nil { return nil, fmt.Errorf("error parsing Tchaik library file: %v\n", err) } fmt.Println("done.") return lib, nil case itlXML != "": f, err := os.Open(itlXML) if err != nil { return nil, fmt.Errorf("could open iTunes library file: %v", err) } defer f.Close() lib, err = itl.ReadFrom(f) if err != nil { return nil, fmt.Errorf("error parsing iTunes library file: %v", err) } case walkPath != "": fmt.Printf("Walking %v...\n", walkPath) lib = walk.NewLibrary(walkPath) fmt.Println("Finished walking.") } fmt.Printf("Building Tchaik Library...") lib = index.Convert(lib, "TrackID") fmt.Println("done.") return lib, nil }