update to latest sentriz/taggolib
This commit is contained in:
4
go.mod
4
go.mod
@@ -3,7 +3,6 @@ module github.com/sentriz/gonic
|
|||||||
require (
|
require (
|
||||||
cloud.google.com/go v0.37.1 // indirect
|
cloud.google.com/go v0.37.1 // indirect
|
||||||
github.com/denisenkom/go-mssqldb v0.0.0-20190315220205-a8ed825ac853 // indirect
|
github.com/denisenkom/go-mssqldb v0.0.0-20190315220205-a8ed825ac853 // indirect
|
||||||
github.com/eaburns/bit v0.0.0-20131029213740-7bd5cd37375d // indirect
|
|
||||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
|
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.4.1 // indirect
|
github.com/go-sql-driver/mysql v1.4.1 // indirect
|
||||||
github.com/gobuffalo/genny v0.1.1 // indirect
|
github.com/gobuffalo/genny v0.1.1 // indirect
|
||||||
@@ -19,10 +18,11 @@ require (
|
|||||||
github.com/karrick/godirwalk v1.8.0
|
github.com/karrick/godirwalk v1.8.0
|
||||||
github.com/lib/pq v1.0.0 // indirect
|
github.com/lib/pq v1.0.0 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.10.0 // indirect
|
github.com/mattn/go-sqlite3 v1.10.0 // indirect
|
||||||
|
github.com/mdlayher/taggolib v0.0.0-20140723044655-d71b09674cfe
|
||||||
github.com/peterbourgon/ff v1.2.0
|
github.com/peterbourgon/ff v1.2.0
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
|
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
|
||||||
github.com/sentriz/taggolib v0.0.0-20190606182049-26b5d155056e
|
github.com/sentriz/taggolib v0.0.0-20190607155858-4b02868793c0
|
||||||
github.com/wader/gormstore v0.0.0-20190302154359-acb787ba3755
|
github.com/wader/gormstore v0.0.0-20190302154359-acb787ba3755
|
||||||
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect
|
golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd // indirect
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
|
||||||
|
|||||||
8
go.sum
8
go.sum
@@ -132,6 +132,8 @@ 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 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
|
||||||
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
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/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/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
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/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||||
@@ -162,6 +164,12 @@ github.com/sentriz/taggolib v0.0.0-20190606174544-31bc993bccf4 h1:tqGj15O7PcAomj
|
|||||||
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-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 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-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.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.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
|
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ type Track struct {
|
|||||||
Artist *Artist
|
Artist *Artist
|
||||||
ArtistID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
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"`
|
Size int `gorm:"not null" sql:"default: null"`
|
||||||
Duration int `gorm:"not null" sql:"default: null"`
|
Duration int `sql:"default: null"`
|
||||||
Bitrate int `gorm:"not null" sql:"default: null"`
|
Bitrate int `sql:"default: null"`
|
||||||
TagTitle string `sql:"default: null"`
|
TagTitle string `sql:"default: null"`
|
||||||
TagTrackArtist string `sql:"default: null"`
|
TagTrackArtist string `sql:"default: null"`
|
||||||
TagTrackNumber int `sql:"default: null"`
|
TagTrackNumber int `sql:"default: null"`
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/sentriz/gonic/mime"
|
"github.com/sentriz/gonic/mime"
|
||||||
"github.com/sentriz/gonic/model"
|
"github.com/sentriz/gonic/model"
|
||||||
|
"github.com/sentriz/taggolib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -36,6 +37,19 @@ var coverFilenames = map[string]struct{}{
|
|||||||
"front.jpeg": {},
|
"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 {
|
type Scanner struct {
|
||||||
db, tx *gorm.DB
|
db, tx *gorm.DB
|
||||||
musicPath string
|
musicPath string
|
||||||
@@ -262,8 +276,8 @@ func (s *Scanner) handleTrack(it *item) error {
|
|||||||
track.TagTrackArtist = tags.Artist()
|
track.TagTrackArtist = tags.Artist()
|
||||||
track.TagTrackNumber = tags.TrackNumber()
|
track.TagTrackNumber = tags.TrackNumber()
|
||||||
track.TagDiscNumber = tags.DiscNumber()
|
track.TagDiscNumber = tags.DiscNumber()
|
||||||
track.Duration = tags.DurationSecs() // these two should be calculated
|
track.Duration = tags.Duration() // these two should be calculated
|
||||||
track.Bitrate = tags.Bitrate() // from the file instead of tags
|
track.Bitrate = tags.Bitrate() // from the file instead of tags
|
||||||
//
|
//
|
||||||
// set album artist basics
|
// set album artist basics
|
||||||
artist := &model.Artist{}
|
artist := &model.Artist{}
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user