feat(subsonic): cache and use lastfm responses for covers, bios, top songs
This commit is contained in:
@@ -58,6 +58,7 @@ func (db *DB) Migrate(ctx MigrationContext) error {
|
||||
construct(ctx, "202305301718", migratePlayCountToLength),
|
||||
construct(ctx, "202307281628", migrateAlbumArtistsMany2Many),
|
||||
construct(ctx, "202309070009", migrateDeleteArtistCoverField),
|
||||
construct(ctx, "202309131743", migrateArtistInfo),
|
||||
}
|
||||
|
||||
return gormigrate.
|
||||
@@ -605,3 +606,10 @@ func migrateDeleteArtistCoverField(tx *gorm.DB, _ MigrationContext) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func migrateArtistInfo(tx *gorm.DB, _ MigrationContext) error {
|
||||
return tx.AutoMigrate(
|
||||
ArtistInfo{},
|
||||
).
|
||||
Error
|
||||
}
|
||||
|
||||
23
db/model.go
23
db/model.go
@@ -7,6 +7,7 @@ package db
|
||||
// https://www.db-fiddle.com/f/wJ7z8L7mu6ZKaYmWk1xr1p/5
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -32,7 +33,7 @@ func splitIDs(in, sep string) []specid.ID {
|
||||
return ret
|
||||
}
|
||||
|
||||
func joinIds(in []specid.ID, sep string) string {
|
||||
func join[T fmt.Stringer](in []T, sep string) string {
|
||||
if in == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -270,7 +271,7 @@ func (p *PlayQueue) GetItems() []specid.ID {
|
||||
}
|
||||
|
||||
func (p *PlayQueue) SetItems(items []specid.ID) {
|
||||
p.Items = joinIds(items, ",")
|
||||
p.Items = join(items, ",")
|
||||
}
|
||||
|
||||
type TranscodePreference struct {
|
||||
@@ -441,3 +442,21 @@ type InternetRadioStation struct {
|
||||
func (ir *InternetRadioStation) SID() *specid.ID {
|
||||
return &specid.ID{Type: specid.InternetRadioStation, Value: ir.ID}
|
||||
}
|
||||
|
||||
type ArtistInfo struct {
|
||||
ID int `gorm:"primary_key" sql:"type:int REFERENCES artists(id) ON DELETE CASCADE"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time `gorm:"index"`
|
||||
Biography string
|
||||
MusicBrainzID string
|
||||
LastFMURL string
|
||||
ImageURL string
|
||||
SimilarArtists string
|
||||
TopTracks string
|
||||
}
|
||||
|
||||
func (p *ArtistInfo) GetSimilarArtists() []string { return strings.Split(p.SimilarArtists, ";") }
|
||||
func (p *ArtistInfo) SetSimilarArtists(items []string) { p.SimilarArtists = strings.Join(items, ";") }
|
||||
|
||||
func (p *ArtistInfo) GetTopTracks() []string { return strings.Split(p.TopTracks, ";") }
|
||||
func (p *ArtistInfo) SetTopTracks(items []string) { p.TopTracks = strings.Join(items, ";") }
|
||||
|
||||
Reference in New Issue
Block a user