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

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{
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,

View File

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

View File

@ -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 != "" {

View File

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

View File

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