Ejemplo n.º 1
0
func dumpFile(path string) {
	f, err := os.Open(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "os.Open(%s): %s\n", path, err)
		return
	}
	defer f.Close()

	tags, err := id3.ReadFile(f)
	if err != nil {
		fmt.Fprintf(os.Stderr, "id3.Read(%s): %s\n", path, err)
		return
	}

	fmt.Println(path)
	fmt.Printf("Title\t%s\n", tags["title"])
	fmt.Printf("Artist\t%s\n", tags["artist"])
	fmt.Printf("Album\t%s\n", tags["album"])
	fmt.Printf("Year\t%s\n", tags["year"])
	fmt.Printf("Track\t%s\n", tags["track"])
	fmt.Printf("Disc\t%s\n", tags["disc"])
	fmt.Printf("Genre\t%s\n", tags["genre"])
	fmt.Printf("Length\t%s\n", tags["length"])
	fmt.Println()
}
Ejemplo n.º 2
0
func getMp3Info(path string) (Song, error) {
	defer timeTrack(time.Now(), "getMp3Info")
	file, err := os.Open(path)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	// duration, err := mp3.Length(file)
	// if err != nil {
	// 	log.Println(err)
	// 	duration = time.Duration(10000)
	// }

	tags, err := id3.ReadFile(file)
	if err != nil {
		return Song{
			Fullname: "none",
			Title:    "none",
			Artist:   "none",
			Album:    "none",
			Path:     "none",
			Length:   0,
		}, err
	}
	title := tags["title"]
	artist := tags["artist"]
	album := tags["album"]
	fullname := artist + " - " + album + " - " + title
	if title == "" {
		title = path
		fullname = title
	}
	return Song{
		Fullname: fullname,
		Title:    title,
		Artist:   artist,
		Album:    album,
		Path:     path,
		Length:   getMp3Length(path),
	}, nil
}