示例#1
0
文件: main.go 项目: pilu/lyricfind
func lyric(c *lyricfind.Client) {
	territory := getenv("LYRICFIND_SEARCH_TERRITORY")
	if len(os.Args) < 2 {
		fmt.Printf("Usage: lyricfind lyric AMG\n")
		os.Exit(1)
	}

	amg, _ := strconv.Atoi(os.Args[1])
	lr, err := c.Lyric(lyricfind.Territory(territory), useragent, amg)
	if err != nil {
		log.Fatal(err)
	}

	dumpTrack(lr.Track)
}
示例#2
0
文件: main.go 项目: pilu/lyricfind
func search(c *lyricfind.Client) {
	territory := getenv("LYRICFIND_SEARCH_TERRITORY")

	so := &lyricfind.SearchOptions{}
	var list bool

	flag.StringVar(&so.Track, "t", "", "query to execute on track name")
	flag.StringVar(&so.Artist, "a", "", "query to execute on artist name")
	flag.StringVar(&so.Album, "b", "", "query to execute on album name")
	flag.BoolVar(&list, "list", false, "list results")
	flag.BoolVar(&so.OnlyDisplayable, "d", false, "search only on displayable tracks")
	flag.Parse()

	if !list {
		so.OnlyDisplayable = true
	}

	if flag.NFlag() == 0 {
		fmt.Println("At least one of the following flags is required:")
		flag.PrintDefaults()
		os.Exit(1)
	}

	r, err := c.Search(lyricfind.Territory(territory), so)
	if err != nil {
		log.Fatal(err)
	}

	if list {
		for _, t := range r.Tracks {
			fmt.Printf("* %s - by %s [track: %d viewable: %v]\n", t.Title, t.Artist.Name, t.Amg, t.Viewable)
		}
		return
	}

	if len(r.Tracks) < 1 {
		fmt.Println("No results")
		os.Exit(0)
	}

	lr, err := c.Lyric(lyricfind.Territory(territory), useragent, r.Tracks[0].Amg)
	if err != nil {
		log.Fatal(err)
	}

	dumpTrack(lr.Track)
}