Skip to content

🎧 Your Personal Streaming Service

getArtist.view implemented

Deluan94d76cb21276
diff --git a/api/base_api_controller.go b/api/base_api_controller.go
index 07d8fc1e9..5e927faf8 100644
--- a/api/base_api_controller.go
+++ b/api/base_api_controller.go
@@ -142,6 +142,20 @@ func (c *BaseAPIController) ToChildren(entries engine.Entries) []responses.Child
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 {
child := responses.Child{}
child.Id = entry.Id
diff --git a/api/browsing.go b/api/browsing.go
index cdbe919c3..11c443d6e 100644
--- a/api/browsing.go
+++ b/api/browsing.go
@@ -93,6 +93,24 @@ func (c *BrowsingController) GetMusicDirectory() {
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() {
id := c.RequiredParamString("id", "id parameter required")
@@ -118,6 +136,7 @@ func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.
Name: d.Name,
Parent: d.Parent,
PlayCount: d.PlayCount,
+ AlbumCount: d.AlbumCount,
UserRating: d.UserRating,
}
if !d.Starred.IsZero() {
@@ -127,3 +146,19 @@ func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.
dir.Child = c.ToChildren(d.Entries)
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
+}
diff --git a/api/responses/responses.go b/api/responses/responses.go
index f4306b09e..af378778d 100644
--- a/api/responses/responses.go
+++ b/api/responses/responses.go
@@ -24,7 +24,8 @@ type Subsonic struct {
Song *Child `xml:"song,omitempty" json:"song,omitempty"`
// 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 {
@@ -76,6 +77,7 @@ type Child struct {
Parent string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
IsDir bool `xml:"isDir,attr" json:"isDir"`
Title string `xml:"title,attr" json:"title"`
+ Name string `xml:"name,attr" json:"name"`
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
Artist string `xml:"artist,attr,omitempty" json:"artist,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"`
PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,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 -->
*/
}
+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 {
Album []Child `xml:"album" json:"album,omitempty"`
}
diff --git a/conf/router.go b/conf/router.go
index 77eeaefa4..676529e61 100644
--- a/conf/router.go
+++ b/conf/router.go
@@ -25,6 +25,7 @@ func mapEndpoints() {
beego.NSRouter("/getMusicDirectory.view", &api.BrowsingController{}, "*:GetMusicDirectory"),
beego.NSRouter("/getSong.view", &api.BrowsingController{}, "*:GetSong"),
beego.NSRouter("/getArtists.view", &api.BrowsingController{}, "*:GetArtists"),
+ beego.NSRouter("/getArtist.view", &api.BrowsingController{}, "*:GetArtist"),
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
diff --git a/engine/browser.go b/engine/browser.go
index 0df6bbe30..faa8b49e3 100644
--- a/engine/browser.go
+++ b/engine/browser.go
@@ -14,6 +14,7 @@ type Browser interface {
MediaFolders() (domain.MediaFolders, error)
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
Directory(id string) (*DirectoryInfo, error)
+ Artist(id string) (*DirectoryInfo, error)
GetSong(id string) (*Entry, error)
}
@@ -60,6 +61,17 @@ type DirectoryInfo struct {
Starred time.Time
PlayCount int32
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) {
@@ -98,7 +110,11 @@ func (b *browser) GetSong(id string) (*Entry, error) {
}
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))
for i, al := range albums {