mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-15 14:52:22 +03:00
getArtist.view implemented
This commit is contained in:
parent
0a137657fe
commit
94d76cb212
@ -142,6 +142,20 @@ func (c *BaseAPIController) ToChildren(entries engine.Entries) []responses.Child
|
|||||||
return children
|
return children
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BaseAPIController) ToAlbums(entries engine.Entries) []responses.Child {
|
||||||
|
children := make([]responses.Child, len(entries))
|
||||||
|
for i, entry := range entries {
|
||||||
|
children[i] = c.ToAlbum(entry)
|
||||||
|
}
|
||||||
|
return children
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseAPIController) ToAlbum(entry engine.Entry) responses.Child {
|
||||||
|
album := c.ToChild(entry)
|
||||||
|
album.Name = album.Title
|
||||||
|
return album
|
||||||
|
}
|
||||||
|
|
||||||
func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
|
func (c *BaseAPIController) ToChild(entry engine.Entry) responses.Child {
|
||||||
child := responses.Child{}
|
child := responses.Child{}
|
||||||
child.Id = entry.Id
|
child.Id = entry.Id
|
||||||
|
@ -93,6 +93,24 @@ func (c *BrowsingController) GetMusicDirectory() {
|
|||||||
c.SendResponse(response)
|
c.SendResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BrowsingController) GetArtist() {
|
||||||
|
id := c.RequiredParamString("id", "id parameter required")
|
||||||
|
|
||||||
|
dir, err := c.browser.Artist(id)
|
||||||
|
switch {
|
||||||
|
case err == domain.ErrNotFound:
|
||||||
|
beego.Error("Requested ArtistId", id, "not found:", err)
|
||||||
|
c.SendError(responses.ErrorDataNotFound, "Artist not found")
|
||||||
|
case err != nil:
|
||||||
|
beego.Error(err)
|
||||||
|
c.SendError(responses.ErrorGeneric, "Internal Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
response := c.NewEmpty()
|
||||||
|
response.ArtistWithAlbumsID3 = c.buildArtist(dir)
|
||||||
|
c.SendResponse(response)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *BrowsingController) GetSong() {
|
func (c *BrowsingController) GetSong() {
|
||||||
id := c.RequiredParamString("id", "id parameter required")
|
id := c.RequiredParamString("id", "id parameter required")
|
||||||
|
|
||||||
@ -118,6 +136,7 @@ func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.
|
|||||||
Name: d.Name,
|
Name: d.Name,
|
||||||
Parent: d.Parent,
|
Parent: d.Parent,
|
||||||
PlayCount: d.PlayCount,
|
PlayCount: d.PlayCount,
|
||||||
|
AlbumCount: d.AlbumCount,
|
||||||
UserRating: d.UserRating,
|
UserRating: d.UserRating,
|
||||||
}
|
}
|
||||||
if !d.Starred.IsZero() {
|
if !d.Starred.IsZero() {
|
||||||
@ -127,3 +146,19 @@ func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.
|
|||||||
dir.Child = c.ToChildren(d.Entries)
|
dir.Child = c.ToChildren(d.Entries)
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BrowsingController) buildArtist(d *engine.DirectoryInfo) *responses.ArtistWithAlbumsID3 {
|
||||||
|
dir := &responses.ArtistWithAlbumsID3{
|
||||||
|
Id: d.Id,
|
||||||
|
Name: d.Name,
|
||||||
|
PlayCount: d.PlayCount,
|
||||||
|
AlbumCount: d.AlbumCount,
|
||||||
|
UserRating: d.UserRating,
|
||||||
|
}
|
||||||
|
if !d.Starred.IsZero() {
|
||||||
|
dir.Starred = &d.Starred
|
||||||
|
}
|
||||||
|
|
||||||
|
dir.Album = c.ToAlbums(d.Entries)
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
@ -24,7 +24,8 @@ type Subsonic struct {
|
|||||||
Song *Child `xml:"song,omitempty" json:"song,omitempty"`
|
Song *Child `xml:"song,omitempty" json:"song,omitempty"`
|
||||||
|
|
||||||
// ID3
|
// ID3
|
||||||
Artist *Indexes `xml:"artists,omitempty" json:"artists,omitempty"`
|
Artist *Indexes `xml:"artists,omitempty" json:"artists,omitempty"`
|
||||||
|
ArtistWithAlbumsID3 *ArtistWithAlbumsID3 `xml:"artist,omitempty" json:"artist,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonWrapper struct {
|
type JsonWrapper struct {
|
||||||
@ -76,6 +77,7 @@ type Child struct {
|
|||||||
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||||
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
||||||
Title string `xml:"title,attr" json:"title"`
|
Title string `xml:"title,attr" json:"title"`
|
||||||
|
Name string `xml:"name,attr" json:"name"`
|
||||||
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
||||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||||
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
|
Track int `xml:"track,attr,omitempty" json:"track,omitempty"`
|
||||||
@ -116,11 +118,33 @@ type Directory struct {
|
|||||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||||
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
|
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
|
||||||
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||||
|
|
||||||
|
// ID3
|
||||||
|
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 int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
|
||||||
|
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||||
|
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
||||||
|
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
|
||||||
|
Year int `xml:"year,attr,omitempty" json:"year,omitempty"`
|
||||||
|
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
||||||
|
|
||||||
/*
|
/*
|
||||||
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ArtistWithAlbumsID3 struct {
|
||||||
|
Album []Child `xml:"album" json:"album,omitempty"`
|
||||||
|
Id string `xml:"id,attr" json:"id"`
|
||||||
|
Name string `xml:"name,attr" json:"name"`
|
||||||
|
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||||
|
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"`
|
||||||
|
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
|
||||||
|
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type AlbumList struct {
|
type AlbumList struct {
|
||||||
Album []Child `xml:"album" json:"album,omitempty"`
|
Album []Child `xml:"album" json:"album,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ func mapEndpoints() {
|
|||||||
beego.NSRouter("/getMusicDirectory.view", &api.BrowsingController{}, "*:GetMusicDirectory"),
|
beego.NSRouter("/getMusicDirectory.view", &api.BrowsingController{}, "*:GetMusicDirectory"),
|
||||||
beego.NSRouter("/getSong.view", &api.BrowsingController{}, "*:GetSong"),
|
beego.NSRouter("/getSong.view", &api.BrowsingController{}, "*:GetSong"),
|
||||||
beego.NSRouter("/getArtists.view", &api.BrowsingController{}, "*:GetArtists"),
|
beego.NSRouter("/getArtists.view", &api.BrowsingController{}, "*:GetArtists"),
|
||||||
|
beego.NSRouter("/getArtist.view", &api.BrowsingController{}, "*:GetArtist"),
|
||||||
|
|
||||||
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type Browser interface {
|
|||||||
MediaFolders() (domain.MediaFolders, error)
|
MediaFolders() (domain.MediaFolders, error)
|
||||||
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
|
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
|
||||||
Directory(id string) (*DirectoryInfo, error)
|
Directory(id string) (*DirectoryInfo, error)
|
||||||
|
Artist(id string) (*DirectoryInfo, error)
|
||||||
GetSong(id string) (*Entry, error)
|
GetSong(id string) (*Entry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +61,17 @@ type DirectoryInfo struct {
|
|||||||
Starred time.Time
|
Starred time.Time
|
||||||
PlayCount int32
|
PlayCount int32
|
||||||
UserRating int
|
UserRating int
|
||||||
|
AlbumCount int
|
||||||
|
CoverArt string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *browser) Artist(id string) (*DirectoryInfo, error) {
|
||||||
|
beego.Debug("Found Artist with id", id)
|
||||||
|
a, albums, err := b.retrieveArtist(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b.buildArtistDir(a, albums), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *browser) Directory(id string) (*DirectoryInfo, error) {
|
func (b *browser) Directory(id string) (*DirectoryInfo, error) {
|
||||||
@ -98,7 +110,11 @@ func (b *browser) GetSong(id string) (*Entry, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
|
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
|
||||||
dir := &DirectoryInfo{Id: a.Id, Name: a.Name}
|
dir := &DirectoryInfo{
|
||||||
|
Id: a.Id,
|
||||||
|
Name: a.Name,
|
||||||
|
AlbumCount: a.AlbumCount,
|
||||||
|
}
|
||||||
|
|
||||||
dir.Entries = make(Entries, len(albums))
|
dir.Entries = make(Entries, len(albums))
|
||||||
for i, al := range albums {
|
for i, al := range albums {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user