scanner: add genre support

This commit is contained in:
Duncan Overbruck
2020-03-02 15:31:54 +01:00
parent f03b615583
commit ae31d4a893
2 changed files with 23 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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