package player import ( "fmt" "image" "path/filepath" "strings" "time" ) // Track represents an audio track. type Track struct { // ID is the internal identifier. ID string // Artist is the performing artist. Artist string // Title of the track. Title string // Album the track appears on. Album string // Label the album is released on. Label string // Date the track was published. Date time.Time // Track number. Track int // Disc number. Disc int // Duration is the track length. Duration time.Duration // Format is the audio format. Format string // Genre names. Genre []string // Path is the file path of the track. Path string // Image is the track or album art. Image image.Image } func (t *Track) String() string { if t == nil { return "nil" } return fmt.Sprintf("%s - %s (%d on %s, %s)", t.Artist, t.Title, t.Track, t.Album, t.Duration) } func (t *Track) Eq(o *Track) bool { if t == nil || o == nil { return false } return strings.EqualFold(t.Artist, o.Artist) && strings.EqualFold(t.Title, o.Title) && strings.EqualFold(t.Album, o.Album) && strings.EqualFold(t.Label, o.Label) } // GuessFormat guesses the audio format base on file name. // // TODO(maze): read the container from the file on disk. func GuessFormat(name string) string { switch strings.ToLower(filepath.Ext(name)) { case ".alac", ".m3a", ".m4a": return "ALAC" case ".flac": return "FLAC" case ".mp3": return "MP3" case ".wav": return "WAVE" default: return "Dunno" } }