Add more OpenSubsonic fields

- mediaType
- musicBrainzId (Child)
This commit is contained in:
Deluan 2023-11-28 21:12:28 -05:00
parent f0e25c251d
commit f580c5b8bc
25 changed files with 115 additions and 74 deletions

View File

@ -188,6 +188,8 @@ func childFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
child.BookmarkPosition = mf.BookmarkPosition
child.Comment = mf.Comment
child.Bpm = int32(mf.Bpm)
child.MediaType = responses.MediaTypeSong
child.MusicBrainzId = mf.MbzRecordingID
return child
}
@ -236,6 +238,8 @@ func childFromAlbum(_ context.Context, al model.Album) responses.Child {
child.Played = &al.PlayDate
}
child.UserRating = int32(al.Rating)
child.MediaType = responses.MediaTypeAlbum
child.MusicBrainzId = al.MbzAlbumID
return child
}

View File

@ -10,10 +10,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
]
}

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<albumList>
<album id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></album>
<album id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></album>
</albumList>
</subsonic-response>

View File

@ -8,8 +8,8 @@
"id": "1",
"name": "album",
"artist": "artist",
"userRating": 0,
"genre": "rock",
"userRating": 0,
"genres": [
{
"name": "rock"
@ -29,14 +29,6 @@
"track": 1,
"year": 1985,
"genre": "Rock",
"genres": [
{
"name": "rock"
},
{
"name": "progressive"
}
],
"coverArt": "1",
"size": 8421341,
"contentType": "audio/flac",
@ -47,8 +39,18 @@
"duration": 146,
"bitRate": 320,
"isVideo": false,
"mediaType": "song",
"musicBrainzId": "4321",
"bpm": 127,
"comment": "a comment"
"comment": "a comment",
"genres": [
{
"name": "rock"
},
{
"name": "progressive"
}
]
}
]
}

View File

@ -1,8 +1,8 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<album id="1" name="album" artist="artist" userRating="0" genre="rock" musicBrainzId="1234">
<album id="1" name="album" artist="artist" genre="rock" userRating="0" musicBrainzId="1234">
<genres name="rock"></genres>
<genres name="progressive"></genres>
<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">
<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" mediaType="song" musicBrainzId="4321" bpm="127" comment="a comment">
<genres name="rock"></genres>
<genres name="progressive"></genres>
</song>

View File

@ -11,10 +11,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
},
"position": 123,
"username": "user2",

View File

@ -1,7 +1,7 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<bookmarks>
<bookmark position="123" username="user2" comment="a comment" created="0001-01-01T00:00:00Z" changed="0001-01-01T00:00:00Z">
<entry id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></entry>
<entry id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></entry>
</bookmark>
</bookmarks>
</subsonic-response>

View File

@ -15,14 +15,6 @@
"track": 1,
"year": 1985,
"genre": "Rock",
"genres": [
{
"name": "rock"
},
{
"name": "progressive"
}
],
"coverArt": "1",
"size": 8421341,
"contentType": "audio/flac",
@ -33,8 +25,18 @@
"duration": 146,
"bitRate": 320,
"isVideo": false,
"mediaType": "song",
"musicBrainzId": "4321",
"bpm": 127,
"comment": "a comment"
"comment": "a comment",
"genres": [
{
"name": "rock"
},
{
"name": "progressive"
}
]
}
],
"id": "1",

View File

@ -1,6 +1,6 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<directory id="1" name="N">
<child 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">
<child 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" mediaType="song" musicBrainzId="4321" bpm="127" comment="a comment">
<genres name="rock"></genres>
<genres name="progressive"></genres>
</child>

View File

@ -9,10 +9,12 @@
{
"id": "1",
"isDir": false,
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
],
"id": "",

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<directory id="" name="">
<child id="1" isDir="false" isVideo="false" bpm="0" comment=""></child>
<child id="1" isDir="false" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></child>
</directory>
</subsonic-response>

View File

@ -10,10 +10,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
],
"id": "1",

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<directory id="1" name="N">
<child id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></child>
<child id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></child>
</directory>
</subsonic-response>

View File

@ -10,10 +10,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
],
"current": "111",

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<playQueue current="111" position="243" username="user1" changed="0001-01-01T00:00:00Z" changedBy="a_client">
<entry id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></entry>
<entry id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></entry>
</playQueue>
</subsonic-response>

View File

@ -14,11 +14,13 @@
"title": "title",
"album": "album",
"artist": "artist",
"genres": [],
"duration": 120,
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
},
{
"id": "2",
@ -26,11 +28,13 @@
"title": "title 2",
"album": "album",
"artist": "artist",
"genres": [],
"duration": 300,
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
],
"id": "ABC123",

View File

@ -1,8 +1,8 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<shares>
<share id="ABC123" url="http://localhost/p/ABC123" description="Check it out!" username="deluan" created="0001-01-01T00:00:00Z" expires="0001-01-01T00:00:00Z" lastVisited="0001-01-01T00:00:00Z" visitCount="2">
<entry id="1" isDir="false" title="title" album="album" artist="artist" duration="120" isVideo="false" bpm="0" comment=""></entry>
<entry id="2" isDir="false" title="title 2" album="album" artist="artist" duration="300" isVideo="false" bpm="0" comment=""></entry>
<entry id="1" isDir="false" title="title" album="album" artist="artist" duration="120" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></entry>
<entry id="2" isDir="false" title="title 2" album="album" artist="artist" duration="300" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></entry>
</share>
</shares>
</subsonic-response>

View File

@ -10,10 +10,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
]
}

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<similarSongs>
<song id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></song>
<song id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></song>
</similarSongs>
</subsonic-response>

View File

@ -10,10 +10,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
]
}

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<similarSongs2>
<song id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></song>
<song id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></song>
</similarSongs2>
</subsonic-response>

View File

@ -10,10 +10,12 @@
"id": "1",
"isDir": false,
"title": "title",
"genres": [],
"isVideo": false,
"mediaType": "",
"musicBrainzId": "",
"bpm": 0,
"comment": ""
"comment": "",
"genres": []
}
]
}

View File

@ -1,5 +1,5 @@
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0" type="navidrome" serverVersion="v0.0.0" openSubsonic="true">
<topSongs>
<song id="1" isDir="false" title="title" isVideo="false" bpm="0" comment=""></song>
<song id="1" isDir="false" title="title" isVideo="false" mediaType="" musicBrainzId="" bpm="0" comment=""></song>
</topSongs>
</subsonic-response>

View File

@ -106,6 +106,14 @@ type Indexes struct {
IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
}
type MediaType string
const (
MediaTypeSong MediaType = "song"
MediaTypeAlbum MediaType = "album"
MediaTypeArtist MediaType = "artist"
)
type Child struct {
Id string `xml:"id,attr" json:"id"`
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
@ -117,7 +125,6 @@ type Child struct {
Track int32 `xml:"track,attr,omitempty" json:"track,omitempty"`
Year int32 `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
Genres ItemGenres `xml:"genres" json:"genres"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
Size int64 `xml:"size,attr,omitempty" json:"size,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
@ -129,7 +136,6 @@ type Child struct {
BitRate int32 `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playCount,omitempty"`
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
DiscNumber int32 `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
@ -139,11 +145,16 @@ type Child struct {
SongCount int32 `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
IsVideo bool `xml:"isVideo,attr" json:"isVideo"`
BookmarkPosition int64 `xml:"bookmarkPosition,attr,omitempty" json:"bookmarkPosition,omitempty"`
Bpm int32 `xml:"bpm,attr" json:"bpm"`
Comment string `xml:"comment,attr" json:"comment"`
/*
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.6.0 -->
*/
// OpenSubsonic extensions
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
MediaType MediaType `xml:"mediaType,attr" json:"mediaType"`
MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"`
Bpm int32 `xml:"bpm,attr" json:"bpm"`
Comment string `xml:"comment,attr" json:"comment"`
Genres ItemGenres `xml:"genres" json:"genres"`
}
type Songs struct {
@ -188,22 +199,24 @@ type ArtistID3 struct {
}
type AlbumID3 struct {
Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
ArtistId string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
SongCount int32 `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
Duration int32 `xml:"duration,attr,omitempty" json:"duration,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playCount,omitempty"`
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int32 `xml:"userRating,attr" json:"userRating"`
Year int32 `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
Genres ItemGenres `xml:"genres" json:"genres"`
MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"`
Id string `xml:"id,attr" json:"id"`
Name string `xml:"name,attr" json:"name"`
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
ArtistId string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
SongCount int32 `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
Duration int32 `xml:"duration,attr,omitempty" json:"duration,omitempty"`
PlayCount int64 `xml:"playCount,attr,omitempty" json:"playCount,omitempty"`
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
Year int32 `xml:"year,attr,omitempty" json:"year,omitempty"`
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
// OpenSubsonic extensions
Played *time.Time `xml:"played,attr,omitempty" json:"played,omitempty"`
UserRating int32 `xml:"userRating,attr" json:"userRating"`
Genres ItemGenres `xml:"genres" json:"genres"`
MusicBrainzId string `xml:"musicBrainzId,attr" json:"musicBrainzId"`
}
type ArtistWithAlbumsID3 struct {

View File

@ -142,7 +142,7 @@ var _ = Describe("Responses", func() {
Year: 1985, Genre: "Rock", CoverArt: "1", Size: 8421341, ContentType: "audio/flac",
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
Duration: 146, BitRate: 320, Starred: &t, Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}},
Comment: "a comment", Bpm: 127,
Comment: "a comment", Bpm: 127, MediaType: MediaTypeSong, MusicBrainzId: "4321",
}
response.Directory.Child = child
})
@ -179,7 +179,7 @@ var _ = Describe("Responses", func() {
Year: 1985, Genre: "Rock", CoverArt: "1", Size: 8421341, ContentType: "audio/flac",
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
Duration: 146, BitRate: 320, Starred: &t, Genres: []ItemGenre{{Name: "rock"}, {Name: "progressive"}},
Comment: "a comment", Bpm: 127,
Comment: "a comment", Bpm: 127, MediaType: MediaTypeSong, MusicBrainzId: "4321",
}}
response.AlbumWithSongsID3.AlbumID3 = album
response.AlbumWithSongsID3.Song = songs