diff --git a/scanner/scanner.go b/scanner/scanner.go index 6efd758..62b828a 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -283,8 +283,7 @@ func (s *Scanner) handleTrack(it *item) error { // set album if this is the first track in the folder folder := s.curFolder() if !folder.ReceivedPaths || folder.ReceivedTags { - // the folder hasn't been modified - // or already has it's tags + // the folder hasn't been modified or already has it's tags return nil } folder.TagTitle = tags.Album() diff --git a/scanner/tags.go b/scanner/tags.go index 5ac7f95..e75d417 100644 --- a/scanner/tags.go +++ b/scanner/tags.go @@ -8,6 +8,31 @@ import ( "github.com/pkg/errors" ) +type tags struct { + map_ map[string]string + props *audiotags.AudioProperties +} + +func readTags(path string) (*tags, error) { + map_, props, err := audiotags.Read(path) + if err != nil { + return nil, errors.Wrap(err, "audiotags module") + } + return &tags{ + map_: map_, + props: props, + }, nil +} + +func (t *tags) firstTag(keys ...string) string { + for _, key := range keys { + if val, ok := t.map_[key]; ok { + return val + } + } + return "" +} + func intSep(in, sep string) int { if in == "" { return 0 @@ -20,20 +45,6 @@ func intSep(in, sep string) int { return out } -type tags struct { - map_ map[string]string - props *audiotags.AudioProperties -} - -func (t *tags) firstTag(keys ...string) string { - for _, key := range keys { - if val, ok := t.map_[key]; ok { - return val - } - } - return "" -} - func (t *tags) Title() string { return t.firstTag("title") } func (t *tags) Artist() string { return t.firstTag("artist") } func (t *tags) Album() string { return t.firstTag("album") } @@ -43,14 +54,3 @@ func (t *tags) TrackNumber() int { return intSep(t.firstTag("tracknumber"), " func (t *tags) DiscNumber() int { return intSep(t.firstTag("discnumber"), "/") } // eg. 1/2 func (t *tags) Length() int { return t.props.Length } func (t *tags) Bitrate() int { return t.props.Bitrate } - -func readTags(path string) (*tags, error) { - map_, props, err := audiotags.Read(path) - if err != nil { - return nil, errors.Wrap(err, "audiotags module") - } - return &tags{ - map_: map_, - props: props, - }, nil -}