scanner: add genre support
This commit is contained in:
@@ -361,6 +361,27 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
s.trTx.Save(artist)
|
||||
}
|
||||
track.ArtistID = artist.ID
|
||||
//
|
||||
// set genre
|
||||
genreName := func() string {
|
||||
if r := trTags.Genre(); r != "" {
|
||||
return r
|
||||
}
|
||||
return "Unknown Genre"
|
||||
}()
|
||||
genre := &db.Genre{}
|
||||
err = s.trTx.
|
||||
Select("id").
|
||||
Where("name=?", genreName).
|
||||
First(genre).
|
||||
Error
|
||||
if gorm.IsRecordNotFoundError(err) {
|
||||
genre.Name = genreName
|
||||
s.trTx.Save(genre)
|
||||
}
|
||||
track.TagGenreID = genre.ID
|
||||
//
|
||||
// save the track
|
||||
s.trTx.Save(track)
|
||||
s.seenTracks[track.ID] = struct{}{}
|
||||
s.seenTracksNew++
|
||||
@@ -376,6 +397,7 @@ func (s *Scanner) handleTrack(it *item) error {
|
||||
folder.TagBrainzID = trTags.AlbumBrainzID()
|
||||
folder.TagYear = trTags.Year()
|
||||
folder.TagArtistID = artist.ID
|
||||
folder.TagGenreID = genre.ID
|
||||
folder.ReceivedTags = true
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ 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) AlbumBrainzID() string { return t.firstTag("musicbrainz_albumid") }
|
||||
func (t *Tags) Genre() string { return t.firstTag("genre") }
|
||||
func (t *Tags) Year() int { return intSep(t.firstTag("date", "year"), "-") } // eg. 2019-6-11
|
||||
func (t *Tags) TrackNumber() int { return intSep(t.firstTag("tracknumber"), "/") } // eg. 5/12
|
||||
func (t *Tags) DiscNumber() int { return intSep(t.firstTag("discnumber"), "/") } // eg. 1/2
|
||||
|
||||
Reference in New Issue
Block a user