mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-05 21:47:36 +03:00
Convert internal disc number representation to int
This commit is contained in:
parent
2c9035fdd0
commit
465cc091b0
5 changed files with 11 additions and 31 deletions
|
@ -1,7 +1,6 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/utils/slice"
|
"github.com/navidrome/navidrome/utils/slice"
|
||||||
|
@ -62,13 +61,14 @@ func (a Album) CoverArtID() ArtworkID {
|
||||||
return artworkIDFromAlbum(a)
|
return artworkIDFromAlbum(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Discs map[string]string
|
type Discs map[int]string
|
||||||
|
|
||||||
|
// Add adds a disc to the Discs map. If the map is nil, it is initialized.
|
||||||
func (d *Discs) Add(discNumber int, discSubtitle string) {
|
func (d *Discs) Add(discNumber int, discSubtitle string) {
|
||||||
if *d == nil {
|
if *d == nil {
|
||||||
*d = Discs{}
|
*d = Discs{}
|
||||||
}
|
}
|
||||||
(*d)[strconv.Itoa(discNumber)] = discSubtitle
|
(*d)[discNumber] = discSubtitle
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiscID struct {
|
type DiscID struct {
|
||||||
|
|
|
@ -139,7 +139,7 @@ var _ = Describe("MediaFiles", func() {
|
||||||
})
|
})
|
||||||
It("sets the correct Discs", func() {
|
It("sets the correct Discs", func() {
|
||||||
album := mfs.ToAlbum()
|
album := mfs.ToAlbum()
|
||||||
Expect(album.Discs).To(Equal(Discs{"1": "DiscSubtitle"}))
|
Expect(album.Discs).To(Equal(Discs{1: "DiscSubtitle"}))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
When("we have multiple discs", func() {
|
When("we have multiple discs", func() {
|
||||||
|
@ -148,7 +148,7 @@ var _ = Describe("MediaFiles", func() {
|
||||||
})
|
})
|
||||||
It("sets the correct Discs", func() {
|
It("sets the correct Discs", func() {
|
||||||
album := mfs.ToAlbum()
|
album := mfs.ToAlbum()
|
||||||
Expect(album.Discs).To(Equal(Discs{"1": "DiscSubtitle", "2": "DiscSubtitle2"}))
|
Expect(album.Discs).To(Equal(Discs{1: "DiscSubtitle", 2: "DiscSubtitle2"}))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -76,7 +76,7 @@ var _ = Describe("AlbumRepository", func() {
|
||||||
Expect(other.Album.Discs).To(Equal(a.Discs))
|
Expect(other.Album.Discs).To(Equal(a.Discs))
|
||||||
})
|
})
|
||||||
It("maps the discs field", func() {
|
It("maps the discs field", func() {
|
||||||
a.Discs = model.Discs{"1": "disc1", "2": "disc2"}
|
a.Discs = model.Discs{1: "disc1", 2: "disc2"}
|
||||||
dba := dbAlbum{Album: a}
|
dba := dbAlbum{Album: a}
|
||||||
|
|
||||||
m := structs.Map(dba)
|
m := structs.Map(dba)
|
||||||
|
|
|
@ -6,11 +6,9 @@ import (
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
"github.com/navidrome/navidrome/log"
|
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
"github.com/navidrome/navidrome/model/request"
|
"github.com/navidrome/navidrome/model/request"
|
||||||
"github.com/navidrome/navidrome/server/public"
|
"github.com/navidrome/navidrome/server/public"
|
||||||
|
@ -271,18 +269,13 @@ func buildItemGenres(genres model.Genres) []responses.ItemGenre {
|
||||||
return itemGenres
|
return itemGenres
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildDiscSubtitles(ctx context.Context, a model.Album) responses.DiscTitles {
|
func buildDiscSubtitles(_ context.Context, a model.Album) responses.DiscTitles {
|
||||||
if len(a.Discs) == 0 {
|
if len(a.Discs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
discTitles := responses.DiscTitles{}
|
discTitles := responses.DiscTitles{}
|
||||||
for num, title := range a.Discs {
|
for num, title := range a.Discs {
|
||||||
n, err := strconv.Atoi(num)
|
discTitles = append(discTitles, responses.DiscTitle{Disc: num, Title: title})
|
||||||
if err != nil {
|
|
||||||
log.Warn(ctx, "Invalid disc number", "num", num, "title", title, "album", a.Name, "artist", a.AlbumArtist, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
discTitles = append(discTitles, responses.DiscTitle{Disc: n, Title: title})
|
|
||||||
}
|
}
|
||||||
sort.Slice(discTitles, func(i, j int) bool {
|
sort.Slice(discTitles, func(i, j int) bool {
|
||||||
return discTitles[i].Disc < discTitles[j].Disc
|
return discTitles[i].Disc < discTitles[j].Disc
|
||||||
|
|
|
@ -45,9 +45,9 @@ var _ = Describe("helpers", func() {
|
||||||
|
|
||||||
It("should return correct disc titles when album has discs with valid disc numbers", func() {
|
It("should return correct disc titles when album has discs with valid disc numbers", func() {
|
||||||
album := model.Album{
|
album := model.Album{
|
||||||
Discs: map[string]string{
|
Discs: map[int]string{
|
||||||
"1": "Disc 1",
|
1: "Disc 1",
|
||||||
"2": "Disc 2",
|
2: "Disc 2",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := responses.DiscTitles{
|
expected := responses.DiscTitles{
|
||||||
|
@ -56,18 +56,5 @@ var _ = Describe("helpers", func() {
|
||||||
}
|
}
|
||||||
Expect(buildDiscSubtitles(context.Background(), album)).To(Equal(expected))
|
Expect(buildDiscSubtitles(context.Background(), album)).To(Equal(expected))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should skip discs with invalid disc numbers", func() {
|
|
||||||
album := model.Album{
|
|
||||||
Discs: map[string]string{
|
|
||||||
"1": "Disc 1",
|
|
||||||
"two": "Disc 2",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
expected := responses.DiscTitles{
|
|
||||||
{Disc: 1, Title: "Disc 1"},
|
|
||||||
}
|
|
||||||
Expect(buildDiscSubtitles(context.Background(), album)).To(Equal(expected))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue