fix: various album_artists <-> artists mismatches

This commit is contained in:
Deluan 2020-03-26 09:08:53 -04:00
parent 5331732236
commit dcb3b3b5d1
7 changed files with 40 additions and 24 deletions

View File

@ -1,6 +1,9 @@
package consts package consts
import ( import (
"crypto/md5"
"fmt"
"strings"
"time" "time"
) )
@ -43,7 +46,9 @@ var (
} }
) )
const ( var (
VariousArtists = "Various Artists" VariousArtists = "Various Artists"
UnknownArtist = "[Unknown Artist]" VariousArtistsID = fmt.Sprintf("%x", md5.Sum([]byte(strings.ToLower(VariousArtists))))
UnknownArtist = "[Unknown Artist]"
UnknownArtistID = fmt.Sprintf("%x", md5.Sum([]byte(strings.ToLower(UnknownArtist))))
) )

View File

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

View File

@ -155,9 +155,9 @@ func (b *browser) buildAlbumDir(al *model.Album, tracks model.MediaFiles) *Direc
dir := &DirectoryInfo{ dir := &DirectoryInfo{
Id: al.ID, Id: al.ID,
Name: al.Name, Name: al.Name,
Parent: al.ArtistID, Parent: al.AlbumArtistID,
Artist: al.Artist, Artist: al.AlbumArtist,
ArtistId: al.ArtistID, ArtistId: al.AlbumArtistID,
SongCount: al.SongCount, SongCount: al.SongCount,
Duration: int(al.Duration), Duration: int(al.Duration),
Created: al.CreatedAt, Created: al.CreatedAt,

View File

@ -63,7 +63,7 @@ func FromAlbum(al *model.Album) Entry {
e.Id = al.ID e.Id = al.ID
e.Title = al.Name e.Title = al.Name
e.IsDir = true e.IsDir = true
e.Parent = al.ArtistID e.Parent = al.AlbumArtistID
e.Album = al.Name e.Album = al.Name
e.Year = al.Year e.Year = al.Year
e.Artist = al.AlbumArtist e.Artist = al.AlbumArtist
@ -71,7 +71,7 @@ func FromAlbum(al *model.Album) Entry {
e.CoverArt = al.CoverArtId e.CoverArt = al.CoverArtId
e.Created = al.CreatedAt e.Created = al.CreatedAt
e.AlbumId = al.ID e.AlbumId = al.ID
e.ArtistId = al.ArtistID e.ArtistId = al.AlbumArtistID
e.Duration = int(al.Duration) e.Duration = int(al.Duration)
e.SongCount = al.SongCount e.SongCount = al.SongCount
if al.Starred { if al.Starred {

View File

@ -121,9 +121,11 @@ func (r *albumRepository) Refresh(ids ...string) error {
} }
if al.Compilation { if al.Compilation {
al.AlbumArtist = consts.VariousArtists al.AlbumArtist = consts.VariousArtists
al.AlbumArtistID = consts.VariousArtistsID
} }
if al.AlbumArtist == "" { if al.AlbumArtist == "" {
al.AlbumArtist = al.Artist al.AlbumArtist = al.Artist
al.AlbumArtistID = al.ArtistID
} }
al.UpdatedAt = time.Now() al.UpdatedAt = time.Now()
if al.CurrentId != "" { if al.CurrentId != "" {

View File

@ -8,7 +8,6 @@ import (
. "github.com/Masterminds/squirrel" . "github.com/Masterminds/squirrel"
"github.com/astaxie/beego/orm" "github.com/astaxie/beego/orm"
"github.com/deluan/navidrome/conf" "github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log" "github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model" "github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/utils" "github.com/deluan/navidrome/utils"
@ -109,13 +108,10 @@ func (r *artistRepository) GetIndex() (model.ArtistIndexes, error) {
func (r *artistRepository) Refresh(ids ...string) error { func (r *artistRepository) Refresh(ids ...string) error {
type refreshArtist struct { type refreshArtist struct {
model.Artist model.Artist
CurrentId string CurrentId string
AlbumArtist string
Compilation bool
} }
var artists []refreshArtist var artists []refreshArtist
sel := Select("f.album_artist_id as id", "f.artist as name", "f.album_artist", "f.compilation", sel := Select("f.album_artist_id as id", "f.album_artist as name", "count(*) as album_count", "a.id as current_id").
"count(*) as album_count", "a.id as current_id").
From("album f"). From("album f").
LeftJoin("artist a on f.album_artist_id = a.id"). LeftJoin("artist a on f.album_artist_id = a.id").
Where(Eq{"f.album_artist_id": ids}). Where(Eq{"f.album_artist_id": ids}).
@ -128,12 +124,6 @@ func (r *artistRepository) Refresh(ids ...string) error {
toInsert := 0 toInsert := 0
toUpdate := 0 toUpdate := 0
for _, ar := range artists { for _, ar := range artists {
if ar.Compilation {
ar.AlbumArtist = consts.VariousArtists
}
if ar.AlbumArtist != "" {
ar.Name = ar.AlbumArtist
}
if ar.CurrentId != "" { if ar.CurrentId != "" {
toUpdate++ toUpdate++
} else { } else {
@ -161,7 +151,7 @@ func (r *artistRepository) GetStarred(options ...model.QueryOptions) (model.Arti
} }
func (r *artistRepository) PurgeEmpty() error { 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) c, err := r.executeSQL(del)
if err == nil { if err == nil {
if c > 0 { if c > 0 {

View File

@ -181,7 +181,7 @@ func (s *TagScanner) processChangedDir(ctx context.Context, dir string, updatedA
numPurgedTracks := 0 numPurgedTracks := 0
for _, n := range newTracks { for _, n := range newTracks {
err := s.ds.MediaFile(ctx).Put(&n) err := s.ds.MediaFile(ctx).Put(&n)
updatedArtists[n.ArtistID] = true updatedArtists[n.AlbumArtistID] = true
updatedAlbums[n.AlbumID] = true updatedAlbums[n.AlbumID] = true
numUpdatedTracks++ numUpdatedTracks++
if err != nil { 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 // Remaining tracks from DB that are not in the folder are deleted
for _, ct := range currentTracks { for _, ct := range currentTracks {
numPurgedTracks++ numPurgedTracks++
updatedArtists[ct.ArtistID] = true updatedArtists[ct.AlbumArtistID] = true
updatedAlbums[ct.AlbumID] = true updatedAlbums[ct.AlbumID] = true
if err := s.ds.MediaFile(ctx).Delete(ct.ID); err != nil { if err := s.ds.MediaFile(ctx).Delete(ct.ID); err != nil {
return err return err
@ -212,7 +212,7 @@ func (s *TagScanner) processDeletedDir(ctx context.Context, dir string, updatedA
return err return err
} }
for _, t := range ct { for _, t := range ct {
updatedArtists[t.ArtistID] = true updatedArtists[t.AlbumArtistID] = true
updatedAlbums[t.AlbumID] = true updatedAlbums[t.AlbumID] = true
} }