mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-16 07:12:24 +03:00
Implement originalReleaseDate
in OpenSubsonic responses. (#2733)
See https://github.com/opensubsonic/open-subsonic-api/pull/80
This commit is contained in:
parent
3f349b1b58
commit
15e1394fa3
@ -7,6 +7,7 @@ import (
|
|||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/navidrome/navidrome/consts"
|
"github.com/navidrome/navidrome/consts"
|
||||||
@ -244,6 +245,24 @@ func childrenFromAlbums(ctx context.Context, als model.Albums) []responses.Child
|
|||||||
return children
|
return children
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toItemDate converts a string date in the formats 'YYYY-MM-DD', 'YYYY-MM' or 'YYYY' to an OS ItemDate
|
||||||
|
func toItemDate(date string) responses.ItemDate {
|
||||||
|
itemDate := responses.ItemDate{}
|
||||||
|
if date == "" {
|
||||||
|
return itemDate
|
||||||
|
}
|
||||||
|
parts := strings.Split(date, "-")
|
||||||
|
if len(parts) > 2 {
|
||||||
|
itemDate.Day, _ = strconv.Atoi(parts[2])
|
||||||
|
}
|
||||||
|
if len(parts) > 1 {
|
||||||
|
itemDate.Month, _ = strconv.Atoi(parts[1])
|
||||||
|
}
|
||||||
|
itemDate.Year, _ = strconv.Atoi(parts[0])
|
||||||
|
|
||||||
|
return itemDate
|
||||||
|
}
|
||||||
|
|
||||||
func buildItemGenres(genres model.Genres) []responses.ItemGenre {
|
func buildItemGenres(genres model.Genres) []responses.ItemGenre {
|
||||||
itemGenres := make([]responses.ItemGenre, len(genres))
|
itemGenres := make([]responses.ItemGenre, len(genres))
|
||||||
for i, g := range genres {
|
for i, g := range genres {
|
||||||
@ -301,5 +320,6 @@ func buildAlbumID3(ctx context.Context, album model.Album) responses.AlbumID3 {
|
|||||||
dir.MusicBrainzId = album.MbzAlbumID
|
dir.MusicBrainzId = album.MbzAlbumID
|
||||||
dir.IsCompilation = album.Compilation
|
dir.IsCompilation = album.Compilation
|
||||||
dir.SortName = album.SortAlbumName
|
dir.SortName = album.SortAlbumName
|
||||||
|
dir.OriginalReleaseDate = toItemDate(album.OriginalDate)
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
@ -57,4 +57,15 @@ var _ = Describe("helpers", func() {
|
|||||||
Expect(buildDiscSubtitles(context.Background(), album)).To(Equal(expected))
|
Expect(buildDiscSubtitles(context.Background(), album)).To(Equal(expected))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
DescribeTable("toItemDate",
|
||||||
|
func(date string, expected responses.ItemDate) {
|
||||||
|
Expect(toItemDate(date)).To(Equal(expected))
|
||||||
|
},
|
||||||
|
Entry("1994-02-04", "1994-02-04", responses.ItemDate{Year: 1994, Month: 2, Day: 4}),
|
||||||
|
Entry("1994-02", "1994-02", responses.ItemDate{Year: 1994, Month: 2}),
|
||||||
|
Entry("1994", "1994", responses.ItemDate{Year: 1994}),
|
||||||
|
Entry("19940201", "", responses.ItemDate{}),
|
||||||
|
Entry("", "", responses.ItemDate{}),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
@ -31,6 +31,11 @@
|
|||||||
"title": "disc 2"
|
"title": "disc 2"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"originalReleaseDate": {
|
||||||
|
"year": 1994,
|
||||||
|
"month": 2,
|
||||||
|
"day": 4
|
||||||
|
},
|
||||||
"song": [
|
"song": [
|
||||||
{
|
{
|
||||||
"id": "1",
|
"id": "1",
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<genres name="progressive"></genres>
|
<genres name="progressive"></genres>
|
||||||
<discTitles disc="1" title="disc 1"></discTitles>
|
<discTitles disc="1" title="disc 1"></discTitles>
|
||||||
<discTitles disc="2" title="disc 2"></discTitles>
|
<discTitles disc="2" title="disc 2"></discTitles>
|
||||||
|
<originalReleaseDate year="1994" month="2" day="4"></originalReleaseDate>
|
||||||
<song id="1" isDir="true" title="title" album="album" artist="artist" track="1" year="1985" genre="Rock" coverArt="1" size="8421341" contentType="audio/flac" suffix="flac" starred="2016-03-02T20:30:00Z" transcodedContentType="audio/mpeg" transcodedSuffix="mp3" duration="146" bitRate="320" isVideo="false" bpm="127" comment="a comment" sortName="sorted song" mediaType="song" musicBrainzId="4321">
|
<song id="1" isDir="true" title="title" album="album" artist="artist" track="1" year="1985" genre="Rock" coverArt="1" size="8421341" contentType="audio/flac" suffix="flac" starred="2016-03-02T20:30:00Z" transcodedContentType="audio/mpeg" transcodedSuffix="mp3" duration="146" bitRate="320" isVideo="false" bpm="127" comment="a comment" sortName="sorted song" mediaType="song" musicBrainzId="4321">
|
||||||
<genres name="rock"></genres>
|
<genres name="rock"></genres>
|
||||||
<genres name="progressive"></genres>
|
<genres name="progressive"></genres>
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
"musicBrainzId": "",
|
"musicBrainzId": "",
|
||||||
"isCompilation": false,
|
"isCompilation": false,
|
||||||
"sortName": "",
|
"sortName": "",
|
||||||
"discTitles": []
|
"discTitles": [],
|
||||||
|
"originalReleaseDate": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
|
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
|
||||||
<album id="" name="" userRating="0" musicBrainzId="" isCompilation="false" sortName=""></album>
|
<album id="" name="" userRating="0" musicBrainzId="" isCompilation="false" sortName="">
|
||||||
|
<originalReleaseDate></originalReleaseDate>
|
||||||
|
</album>
|
||||||
</subsonic-response>
|
</subsonic-response>
|
||||||
|
@ -225,6 +225,7 @@ type AlbumID3 struct {
|
|||||||
IsCompilation bool `xml:"isCompilation,attr" json:"isCompilation"`
|
IsCompilation bool `xml:"isCompilation,attr" json:"isCompilation"`
|
||||||
SortName string `xml:"sortName,attr" json:"sortName"`
|
SortName string `xml:"sortName,attr" json:"sortName"`
|
||||||
DiscTitles DiscTitles `xml:"discTitles" json:"discTitles"`
|
DiscTitles DiscTitles `xml:"discTitles" json:"discTitles"`
|
||||||
|
OriginalReleaseDate ItemDate `xml:"originalReleaseDate" json:"originalReleaseDate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistWithAlbumsID3 struct {
|
type ArtistWithAlbumsID3 struct {
|
||||||
@ -492,3 +493,9 @@ func marshalJSONArray[T any](v []T) ([]byte, error) {
|
|||||||
a := v
|
a := v
|
||||||
return json.Marshal(a)
|
return json.Marshal(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ItemDate struct {
|
||||||
|
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
|
||||||
|
Month int `xml:"month,attr,omitempty" json:"month,omitempty"`
|
||||||
|
Day int `xml:"day,attr,omitempty" json:"day,omitempty"`
|
||||||
|
}
|
||||||
|
@ -177,6 +177,7 @@ var _ = Describe("Responses", func() {
|
|||||||
Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}},
|
Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}},
|
||||||
MusicBrainzId: "1234", IsCompilation: true, SortName: "sorted album",
|
MusicBrainzId: "1234", IsCompilation: true, SortName: "sorted album",
|
||||||
DiscTitles: DiscTitles{{Disc: 1, Title: "disc 1"}, {Disc: 2, Title: "disc 2"}},
|
DiscTitles: DiscTitles{{Disc: 1, Title: "disc 1"}, {Disc: 2, Title: "disc 2"}},
|
||||||
|
OriginalReleaseDate: ItemDate{Year: 1994, Month: 2, Day: 4},
|
||||||
}
|
}
|
||||||
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
|
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
|
||||||
songs := []Child{{
|
songs := []Child{{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user