update to latest sentriz/taggolib

This commit is contained in:
sentriz
2019-06-07 17:13:40 +01:00
parent c96fdf458f
commit 188b52bc61
5 changed files with 28 additions and 62 deletions

View File

@@ -15,6 +15,7 @@ import (
"github.com/sentriz/gonic/mime"
"github.com/sentriz/gonic/model"
"github.com/sentriz/taggolib"
)
var (
@@ -36,6 +37,19 @@ var coverFilenames = map[string]struct{}{
"front.jpeg": {},
}
func readTags(path string) (taggolib.Parser, error) {
track, err := os.Open(path)
if err != nil {
return nil, errors.Wrap(err, "reading disk")
}
defer track.Close()
parser, err := taggolib.New(track)
if err != nil {
return nil, errors.Wrap(err, "parsing")
}
return parser, nil
}
type Scanner struct {
db, tx *gorm.DB
musicPath string
@@ -262,8 +276,8 @@ func (s *Scanner) handleTrack(it *item) error {
track.TagTrackArtist = tags.Artist()
track.TagTrackNumber = tags.TrackNumber()
track.TagDiscNumber = tags.DiscNumber()
track.Duration = tags.DurationSecs() // these two should be calculated
track.Bitrate = tags.Bitrate() // from the file instead of tags
track.Duration = tags.Duration() // these two should be calculated
track.Bitrate = tags.Bitrate() // from the file instead of tags
//
// set album artist basics
artist := &model.Artist{}

View File

@@ -1,56 +0,0 @@
package scanner
import (
"os"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/sentriz/taggolib"
)
type tags struct {
taggolib.Parser
}
func (t *tags) Year() int {
// for this one there could be multiple tags and a
// date separator. so do string(2019-6-6) -> int(2019)
// for the two options and pick the first
for _, name := range []string{"DATE", "YEAR"} {
tag := t.Tag(name)
if tag == "" {
continue
}
parts := strings.Split(tag, "-")
year, err := strconv.Atoi(parts[0])
if err != nil {
continue
}
return year
}
return 0
}
func (t *tags) DurationSecs() int {
duration := int(t.Duration() / 1e9)
if duration == 0 {
return -1
}
return duration
}
func readTags(path string) (*tags, error) {
track, err := os.Open(path)
if err != nil {
return nil, errors.Wrap(err, "reading disk")
}
defer track.Close()
parser, err := taggolib.New(track)
if err != nil {
return nil, errors.Wrap(err, "parsing")
}
newTags := &tags{parser}
return newTags, nil
}