diff --git a/consts/consts.go b/consts/consts.go index 39b6751d..a123959c 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -1,6 +1,9 @@ package consts import ( + "crypto/md5" + "fmt" + "strings" "time" ) @@ -43,7 +46,9 @@ var ( } ) -const ( - VariousArtists = "Various Artists" - UnknownArtist = "[Unknown Artist]" +var ( + VariousArtists = "Various Artists" + VariousArtistsID = fmt.Sprintf("%x", md5.Sum([]byte(strings.ToLower(VariousArtists)))) + UnknownArtist = "[Unknown Artist]" + UnknownArtistID = fmt.Sprintf("%x", md5.Sum([]byte(strings.ToLower(UnknownArtist)))) ) diff --git a/db/migration/20200326090707_fix_album_artists_importing.go b/db/migration/20200326090707_fix_album_artists_importing.go new file mode 100644 index 00000000..05db74bb --- /dev/null +++ b/db/migration/20200326090707_fix_album_artists_importing.go @@ -0,0 +1,19 @@ +package migration + +import ( + "database/sql" + "github.com/pressly/goose" +) + +func init() { + goose.AddMigration(Up20200326090707, Down20200326090707) +} + +func Up20200326090707(tx *sql.Tx) error { + notice(tx, "A full rescan will be performed!") + return forceFullRescan(tx) +} + +func Down20200326090707(tx *sql.Tx) error { + return nil +} diff --git a/engine/browser.go b/engine/browser.go index 3181fb85..3bd3d56c 100644 --- a/engine/browser.go +++ b/engine/browser.go @@ -155,9 +155,9 @@ func (b *browser) buildAlbumDir(al *model.Album, tracks model.MediaFiles) *Direc dir := &DirectoryInfo{ Id: al.ID, Name: al.Name, - Parent: al.ArtistID, - Artist: al.Artist, - ArtistId: al.ArtistID, + Parent: al.AlbumArtistID, + Artist: al.AlbumArtist, + ArtistId: al.AlbumArtistID, SongCount: al.SongCount, Duration: int(al.Duration), Created: al.CreatedAt, diff --git a/engine/common.go b/engine/common.go index e1089096..b50768a2 100644 --- a/engine/common.go +++ b/engine/common.go @@ -63,7 +63,7 @@ func FromAlbum(al *model.Album) Entry { e.Id = al.ID e.Title = al.Name e.IsDir = true - e.Parent = al.ArtistID + e.Parent = al.AlbumArtistID e.Album = al.Name e.Year = al.Year e.Artist = al.AlbumArtist @@ -71,7 +71,7 @@ func FromAlbum(al *model.Album) Entry { e.CoverArt = al.CoverArtId e.Created = al.CreatedAt e.AlbumId = al.ID - e.ArtistId = al.ArtistID + e.ArtistId = al.AlbumArtistID e.Duration = int(al.Duration) e.SongCount = al.SongCount if al.Starred { diff --git a/persistence/album_repository.go b/persistence/album_repository.go index 562a0712..385a952e 100644 --- a/persistence/album_repository.go +++ b/persistence/album_repository.go @@ -121,9 +121,11 @@ func (r *albumRepository) Refresh(ids ...string) error { } if al.Compilation { al.AlbumArtist = consts.VariousArtists + al.AlbumArtistID = consts.VariousArtistsID } if al.AlbumArtist == "" { al.AlbumArtist = al.Artist + al.AlbumArtistID = al.ArtistID } al.UpdatedAt = time.Now() if al.CurrentId != "" { diff --git a/persistence/artist_repository.go b/persistence/artist_repository.go index afddef7b..7496d0f5 100644 --- a/persistence/artist_repository.go +++ b/persistence/artist_repository.go @@ -8,7 +8,6 @@ import ( . "github.com/Masterminds/squirrel" "github.com/astaxie/beego/orm" "github.com/deluan/navidrome/conf" - "github.com/deluan/navidrome/consts" "github.com/deluan/navidrome/log" "github.com/deluan/navidrome/model" "github.com/deluan/navidrome/utils" @@ -109,13 +108,10 @@ func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) { func (r *artistRepository) Refresh(ids ...string) error { type refreshArtist struct { model.Artist - CurrentId string - AlbumArtist string - Compilation bool + CurrentId string } var artists []refreshArtist - sel := Select("f.album_artist_id as id", "f.artist as name", "f.album_artist", "f.compilation", - "count(*) as album_count", "a.id as current_id"). + sel := Select("f.album_artist_id as id", "f.album_artist as name", "count(*) as album_count", "a.id as current_id"). From("album f"). LeftJoin("artist a on f.album_artist_id = a.id"). Where(Eq{"f.album_artist_id": ids}). @@ -128,12 +124,6 @@ func (r *artistRepository) Refresh(ids ...string) error { toInsert := 0 toUpdate := 0 for _, ar := range artists { - if ar.Compilation { - ar.AlbumArtist = consts.VariousArtists - } - if ar.AlbumArtist != "" { - ar.Name = ar.AlbumArtist - } if ar.CurrentId != "" { toUpdate++ } else { @@ -161,7 +151,7 @@ func (r *artistRepository) GetStarred(options ...model.QueryOptions) (model.Arti } func (r *artistRepository) PurgeEmpty() error { - del := Delete(r.tableName).Where("id not in (select distinct(artist_id) from album)") + del := Delete(r.tableName).Where("id not in (select distinct(album_artist_id) from album)") c, err := r.executeSQL(del) if err == nil { if c > 0 { diff --git a/scanner/tag_scanner.go b/scanner/tag_scanner.go index 9572f0f1..2abc500c 100644 --- a/scanner/tag_scanner.go +++ b/scanner/tag_scanner.go @@ -181,7 +181,7 @@ func (s *TagScanner) processChangedDir(ctx context.Context, dir string, updatedA numPurgedTracks := 0 for _, n := range newTracks { err := s.ds.MediaFile(ctx).Put(&n) - updatedArtists[n.ArtistID] = true + updatedArtists[n.AlbumArtistID] = true updatedAlbums[n.AlbumID] = true numUpdatedTracks++ if err != nil { @@ -192,7 +192,7 @@ func (s *TagScanner) processChangedDir(ctx context.Context, dir string, updatedA // Remaining tracks from DB that are not in the folder are deleted for _, ct := range currentTracks { numPurgedTracks++ - updatedArtists[ct.ArtistID] = true + updatedArtists[ct.AlbumArtistID] = true updatedAlbums[ct.AlbumID] = true if err := s.ds.MediaFile(ctx).Delete(ct.ID); err != nil { return err @@ -212,7 +212,7 @@ func (s *TagScanner) processDeletedDir(ctx context.Context, dir string, updatedA return err } for _, t := range ct { - updatedArtists[t.ArtistID] = true + updatedArtists[t.AlbumArtistID] = true updatedAlbums[t.AlbumID] = true }