Added -mbz option to tag tool to output MusicBrainz information.

This commit is contained in:
David Howden 2015-06-06 16:29:25 +10:00
parent e7f103ff85
commit 6cd7fd8f70

View File

@ -8,14 +8,17 @@ The tag tool reads metadata from media files (as supported by the tag library).
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"github.com/dhowden/tag"
"github.com/dhowden/tag/mbz"
)
var raw bool
var extractMBZ bool
var usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [optional flags] filename\n", os.Args[0])
@ -24,6 +27,7 @@ var usage = func() {
func init() {
flag.BoolVar(&raw, "raw", false, "show raw tag data")
flag.BoolVar(&extractMBZ, "mbz", false, "extract MusicBrainz tag data (if available)")
flag.Usage = usage
}
@ -64,6 +68,16 @@ func main() {
fmt.Printf("%#v: %#v\n", k, v)
}
}
if extractMBZ {
b, err := json.MarshalIndent(mbz.Extract(m), "", " ")
if err != nil {
fmt.Printf("error marshalling MusicBrainz info: %v\n", err)
return
}
fmt.Printf("\nMusicBrainz Info:\n%v\n", string(b))
}
}
func printMetadata(m tag.Metadata) {