set a temporary album tag artist for those who mightn't have it yet
This commit is contained in:
@@ -70,6 +70,7 @@ func (db *DB) Migrate(ctx MigrationContext) error {
|
||||
construct(ctx, "202310281803", migrateTrackArtists),
|
||||
construct(ctx, "202311062259", migrateArtistAppearances),
|
||||
construct(ctx, "202311072309", migrateAlbumInfo),
|
||||
construct(ctx, "202311082304", migrateTemporaryDisplayAlbumArtist),
|
||||
}
|
||||
|
||||
return gormigrate.
|
||||
@@ -787,3 +788,17 @@ func migrateAlbumInfo(tx *gorm.DB, _ MigrationContext) error {
|
||||
).
|
||||
Error
|
||||
}
|
||||
|
||||
func migrateTemporaryDisplayAlbumArtist(tx *gorm.DB, _ MigrationContext) error {
|
||||
// keep some things working so that people have an album.tag_artist_id until their next full scan
|
||||
return tx.Exec(`
|
||||
UPDATE albums
|
||||
SET tag_album_artist=(
|
||||
SELECT group_concat(artists.name, ', ')
|
||||
FROM artists
|
||||
JOIN album_artists ON album_artists.artist_id=artists.id AND album_artists.album_id=albums.id
|
||||
GROUP BY album_artists.album_id
|
||||
)
|
||||
WHERE tag_album_artist=''
|
||||
`).Error
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"math"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
@@ -72,7 +70,7 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response {
|
||||
scrobbleTrack.Track = track.TagTitle
|
||||
scrobbleTrack.Artist = track.TagTrackArtist
|
||||
scrobbleTrack.Album = track.Album.TagTitle
|
||||
scrobbleTrack.AlbumArtist = albumArtistString(track.Album)
|
||||
scrobbleTrack.AlbumArtist = track.Album.TagAlbumArtist
|
||||
scrobbleTrack.TrackNumber = uint(track.TagTrackNumber)
|
||||
scrobbleTrack.Duration = time.Second * time.Duration(track.Length)
|
||||
if _, err := uuid.Parse(track.TagBrainzID); err == nil {
|
||||
@@ -517,21 +515,3 @@ func lowerUDecOrHash(in string) string {
|
||||
}
|
||||
return string(lower)
|
||||
}
|
||||
|
||||
// not everyone's records may have the album.TagAlbumArtist column set, since we didn't always store that.
|
||||
// try it first, but fallback to a list from the artists table
|
||||
func albumArtistString(album *db.Album) string {
|
||||
if album.TagAlbumArtist != "" {
|
||||
return album.TagAlbumArtist
|
||||
}
|
||||
|
||||
artists := append([]*db.Artist(nil), album.Artists...)
|
||||
sort.Slice(artists, func(i, j int) bool {
|
||||
return artists[i].ID < artists[j].ID
|
||||
})
|
||||
names := make([]string, 0, len(artists))
|
||||
for _, artist := range artists {
|
||||
names = append(names, artist.Name)
|
||||
}
|
||||
return strings.Join(names, ", ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user