getArtist.view implemented

This commit is contained in:
Deluan 2016-03-27 21:27:45 -04:00
parent 0a137657fe
commit 94d76cb212
5 changed files with 92 additions and 2 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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"`
}

View File

@ -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"),

View File

@ -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 {