move to audiotags

This commit is contained in:
sentriz
2019-06-11 13:42:42 +01:00
parent 435b6c1f8b
commit e5998dca02
7 changed files with 64 additions and 35 deletions

3
go.mod
View File

@@ -18,11 +18,10 @@ require (
github.com/karrick/godirwalk v1.8.0
github.com/lib/pq v1.0.0 // indirect
github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/mdlayher/taggolib v0.0.0-20140723044655-d71b09674cfe
github.com/nicksellen/audiotags v0.0.0-20160226222119-94015fa599bd
github.com/peterbourgon/ff v1.2.0
github.com/pkg/errors v0.8.1
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
github.com/sentriz/taggolib v0.0.0-20190607155858-4b02868793c0
github.com/wader/gormstore v0.0.0-20190302154359-acb787ba3755
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect

16
go.sum
View File

@@ -20,8 +20,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20190315220205-a8ed825ac853 h1:tTngnoO/B6HQnJ+pK8tN7kEAhmhIfaJOutqq/A4/JTM=
github.com/denisenkom/go-mssqldb v0.0.0-20190315220205-a8ed825ac853/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc=
github.com/eaburns/bit v0.0.0-20131029213740-7bd5cd37375d h1:HB5J9+f1xpkYLgWQ/RqEcbp3SEufyOIMYLoyKNKiG7E=
github.com/eaburns/bit v0.0.0-20131029213740-7bd5cd37375d/go.mod h1:CHkHWWZ4kbGY6jEy1+qlitDaCtRgNvCOQdakj/1Yl/Q=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
@@ -132,9 +130,9 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mdlayher/taggolib v0.0.0-20140723044655-d71b09674cfe h1:WyohQTx/GamBIn8NQAH3JrnEk5Tj++eNmwJOexXxNIk=
github.com/mdlayher/taggolib v0.0.0-20140723044655-d71b09674cfe/go.mod h1:11hji841NkL7BD+0rOgSuBzQ7bxBHKUj7Tp01NFZTE0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nicksellen/audiotags v0.0.0-20160226222119-94015fa599bd h1:xKn/gU8lZupoZt/HE7a/R3aH93iUO6JwyRsYelQUsRI=
github.com/nicksellen/audiotags v0.0.0-20160226222119-94015fa599bd/go.mod h1:B6icauz2l4tkYQxmDtCH4qmNWz/evSW5CsOqp6IE5IE=
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/peterbourgon/ff v1.2.0 h1:wGn2NwdHk8MTlRQpnXnO91UKegxt5DvlwR/bTK/L2hc=
@@ -160,16 +158,6 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sentriz/taggolib v0.0.0-20190606174544-31bc993bccf4 h1:tqGj15O7PcAomjThBovGe9xUxCC22WVItQjW9Wo/69M=
github.com/sentriz/taggolib v0.0.0-20190606174544-31bc993bccf4/go.mod h1:c+rVE+i+SSdXptoMgXUoW/ABPT3gn5hXHcySx+L4RzE=
github.com/sentriz/taggolib v0.0.0-20190606182049-26b5d155056e h1:/Vc8Bp4sxpogBPzGRJ1BO9psPQ/bakFsFhghuhCsorY=
github.com/sentriz/taggolib v0.0.0-20190606182049-26b5d155056e/go.mod h1:c+rVE+i+SSdXptoMgXUoW/ABPT3gn5hXHcySx+L4RzE=
github.com/sentriz/taggolib v0.0.0-20190607145701-c214099e9886 h1:MqjQCIXzpDHy1AVb0eY8WUDsQUfFtJ97fj/B1IJtHlw=
github.com/sentriz/taggolib v0.0.0-20190607145701-c214099e9886/go.mod h1:c+rVE+i+SSdXptoMgXUoW/ABPT3gn5hXHcySx+L4RzE=
github.com/sentriz/taggolib v0.0.0-20190607155858-4b02868793c0 h1:g5F6BfCeJyN9Up3qBa9R625e0zsZOBO+XgvGaOO4lps=
github.com/sentriz/taggolib v0.0.0-20190607155858-4b02868793c0/go.mod h1:o4wJ+dzmd16lEw5UsyrLeLetRropx7LA6SGUJQigEic=
github.com/sentriz/taggolib v0.0.0-20190607155922-1ac071004ecf h1:EgT2t9K1jeVfPr9Y0omw+31q52FLPJMaVPlncs1hSlw=
github.com/sentriz/taggolib v0.0.0-20190607155922-1ac071004ecf/go.mod h1:o4wJ+dzmd16lEw5UsyrLeLetRropx7LA6SGUJQigEic=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=

View File

@@ -23,7 +23,7 @@ type Track struct {
Artist *Artist
ArtistID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
Size int `gorm:"not null" sql:"default: null"`
Duration int `sql:"default: null"`
Length int `sql:"default: null"`
Bitrate int `sql:"default: null"`
TagTitle string `sql:"default: null"`
TagTrackArtist string `sql:"default: null"`

View File

@@ -15,7 +15,6 @@ import (
"github.com/sentriz/gonic/mime"
"github.com/sentriz/gonic/model"
"github.com/sentriz/taggolib"
)
var (
@@ -37,19 +36,6 @@ 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
@@ -276,8 +262,8 @@ func (s *Scanner) handleTrack(it *item) error {
track.TagTrackArtist = tags.Artist()
track.TagTrackNumber = tags.TrackNumber()
track.TagDiscNumber = tags.DiscNumber()
track.Duration = tags.Duration() // these two should be calculated
track.Bitrate = tags.Bitrate() // from the file instead of tags
track.Length = tags.Length() // these two should be calculated
track.Bitrate = tags.Bitrate() // from the file instead of tags
//
// set album artist basics
artist := &model.Artist{}

56
scanner/tags.go Normal file
View File

@@ -0,0 +1,56 @@
package scanner
import (
"strconv"
"strings"
"github.com/nicksellen/audiotags"
"github.com/pkg/errors"
)
func intSep(in, sep string) int {
if in == "" {
return 0
}
start := strings.Split(in, sep)[0]
out, err := strconv.Atoi(start)
if err != nil {
return 0
}
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") }
func (t *tags) AlbumArtist() string { return t.firstTag("albumartist", "album artist") }
func (t *tags) Year() int { return intSep(t.firstTag("date", "year"), "-") }
func (t *tags) TrackNumber() int { return intSep(t.firstTag("tracknumber"), "/") }
func (t *tags) DiscNumber() int { return intSep(t.firstTag("discnumber"), "/") }
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
}

View File

@@ -48,7 +48,7 @@ func newTCTrackByFolder(t *model.Track, parent *model.Album) *subsonic.TrackChil
t.Filename,
),
ParentID: parent.ID,
Duration: t.Duration,
Duration: t.Length,
Bitrate: t.Bitrate,
IsDir: false,
Type: "music",

View File

@@ -43,7 +43,7 @@ func newTrackByTags(t *model.Track, album *model.Album) *subsonic.TrackChild {
Album: album.TagTitle,
AlbumID: album.ID,
ArtistID: album.TagArtist.ID,
Duration: t.Duration,
Duration: t.Length,
Bitrate: t.Bitrate,
Type: "music",
}