getAlbum.view implemented
This commit is contained in:
+46
-7
@@ -111,6 +111,24 @@ func (c *BrowsingController) GetArtist() {
|
|||||||
c.SendResponse(response)
|
c.SendResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BrowsingController) GetAlbum() {
|
||||||
|
id := c.RequiredParamString("id", "id parameter required")
|
||||||
|
|
||||||
|
dir, err := c.browser.Album(id)
|
||||||
|
switch {
|
||||||
|
case err == domain.ErrNotFound:
|
||||||
|
beego.Error("Requested AlbumId", id, "not found:", err)
|
||||||
|
c.SendError(responses.ErrorDataNotFound, "Album not found")
|
||||||
|
case err != nil:
|
||||||
|
beego.Error(err)
|
||||||
|
c.SendError(responses.ErrorGeneric, "Internal Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
response := c.NewEmpty()
|
||||||
|
response.AlbumWithSongsID3 = c.buildAlbum(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")
|
||||||
|
|
||||||
@@ -148,13 +166,11 @@ func (c *BrowsingController) buildDirectory(d *engine.DirectoryInfo) *responses.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *BrowsingController) buildArtist(d *engine.DirectoryInfo) *responses.ArtistWithAlbumsID3 {
|
func (c *BrowsingController) buildArtist(d *engine.DirectoryInfo) *responses.ArtistWithAlbumsID3 {
|
||||||
dir := &responses.ArtistWithAlbumsID3{
|
dir := &responses.ArtistWithAlbumsID3{}
|
||||||
Id: d.Id,
|
dir.Id = d.Id
|
||||||
Name: d.Name,
|
dir.Name = d.Name
|
||||||
PlayCount: d.PlayCount,
|
dir.AlbumCount = d.AlbumCount
|
||||||
AlbumCount: d.AlbumCount,
|
dir.CoverArt = d.CoverArt
|
||||||
UserRating: d.UserRating,
|
|
||||||
}
|
|
||||||
if !d.Starred.IsZero() {
|
if !d.Starred.IsZero() {
|
||||||
dir.Starred = &d.Starred
|
dir.Starred = &d.Starred
|
||||||
}
|
}
|
||||||
@@ -162,3 +178,26 @@ func (c *BrowsingController) buildArtist(d *engine.DirectoryInfo) *responses.Art
|
|||||||
dir.Album = c.ToAlbums(d.Entries)
|
dir.Album = c.ToAlbums(d.Entries)
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *BrowsingController) buildAlbum(d *engine.DirectoryInfo) *responses.AlbumWithSongsID3 {
|
||||||
|
dir := &responses.AlbumWithSongsID3{}
|
||||||
|
dir.Id = d.Id
|
||||||
|
dir.Name = d.Name
|
||||||
|
dir.Artist = d.Artist
|
||||||
|
dir.ArtistId = d.ArtistId
|
||||||
|
dir.CoverArt = d.CoverArt
|
||||||
|
dir.SongCount = d.SongCount
|
||||||
|
dir.Duration = d.Duration
|
||||||
|
dir.PlayCount = d.PlayCount
|
||||||
|
dir.Year = d.Year
|
||||||
|
dir.Genre = d.Genre
|
||||||
|
if !d.Created.IsZero() {
|
||||||
|
dir.Created = &d.Created
|
||||||
|
}
|
||||||
|
if !d.Starred.IsZero() {
|
||||||
|
dir.Starred = &d.Starred
|
||||||
|
}
|
||||||
|
|
||||||
|
dir.Song = c.ToChildren(d.Entries)
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type Subsonic struct {
|
|||||||
// 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"`
|
ArtistWithAlbumsID3 *ArtistWithAlbumsID3 `xml:"artist,omitempty" json:"artist,omitempty"`
|
||||||
|
AlbumWithSongsID3 *AlbumWithSongsID3 `xml:"album,omitempty" json:"album,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonWrapper struct {
|
type JsonWrapper struct {
|
||||||
@@ -136,14 +137,37 @@ type Directory struct {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistWithAlbumsID3 struct {
|
type ArtistID3 struct {
|
||||||
Album []Child `xml:"album" json:"album,omitempty"`
|
|
||||||
Id string `xml:"id,attr" json:"id"`
|
Id string `xml:"id,attr" json:"id"`
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,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"`
|
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||||
|
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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 int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
|
||||||
|
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
||||||
|
PlayCount int32 `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 int `xml:"year,attr,omitempty" json:"year,omitempty"`
|
||||||
|
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArtistWithAlbumsID3 struct {
|
||||||
|
ArtistID3
|
||||||
|
Album []Child `xml:"album" json:"album,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AlbumWithSongsID3 struct {
|
||||||
|
AlbumID3
|
||||||
|
Song []Child `xml:"song" json:"song,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlbumList struct {
|
type AlbumList struct {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ func mapEndpoints() {
|
|||||||
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("/getArtist.view", &api.BrowsingController{}, "*:GetArtist"),
|
||||||
|
beego.NSRouter("/getAlbum.view", &api.BrowsingController{}, "*:GetAlbum"),
|
||||||
|
|
||||||
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
||||||
|
|
||||||
|
|||||||
+26
-15
@@ -15,6 +15,7 @@ type Browser interface {
|
|||||||
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)
|
Artist(id string) (*DirectoryInfo, error)
|
||||||
|
Album(id string) (*DirectoryInfo, error)
|
||||||
GetSong(id string) (*Entry, error)
|
GetSong(id string) (*Entry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +64,13 @@ type DirectoryInfo struct {
|
|||||||
UserRating int
|
UserRating int
|
||||||
AlbumCount int
|
AlbumCount int
|
||||||
CoverArt string
|
CoverArt string
|
||||||
|
Artist string
|
||||||
|
ArtistId string
|
||||||
|
SongCount int
|
||||||
|
Duration int
|
||||||
|
Created time.Time
|
||||||
|
Year int
|
||||||
|
Genre string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *browser) Artist(id string) (*DirectoryInfo, error) {
|
func (b *browser) Artist(id string) (*DirectoryInfo, error) {
|
||||||
@@ -74,29 +82,25 @@ func (b *browser) Artist(id string) (*DirectoryInfo, error) {
|
|||||||
return b.buildArtistDir(a, albums), nil
|
return b.buildArtistDir(a, albums), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *browser) Album(id string) (*DirectoryInfo, error) {
|
||||||
|
beego.Debug("Found Album with id", id)
|
||||||
|
al, tracks, err := b.retrieveAlbum(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b.buildAlbumDir(al, tracks), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *browser) Directory(id string) (*DirectoryInfo, error) {
|
func (b *browser) Directory(id string) (*DirectoryInfo, error) {
|
||||||
var dir *DirectoryInfo
|
|
||||||
switch {
|
switch {
|
||||||
case b.isArtist(id):
|
case b.isArtist(id):
|
||||||
beego.Debug("Found Artist with id", id)
|
return b.Artist(id)
|
||||||
a, albums, err := b.retrieveArtist(id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dir = b.buildArtistDir(a, albums)
|
|
||||||
case b.isAlbum(id):
|
case b.isAlbum(id):
|
||||||
beego.Debug("Found Album with id", id)
|
return b.Album(id)
|
||||||
al, tracks, err := b.retrieveAlbum(id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dir = b.buildAlbumDir(al, tracks)
|
|
||||||
default:
|
default:
|
||||||
beego.Debug("Id", id, "not found")
|
beego.Debug("Id", id, "not found")
|
||||||
return nil, domain.ErrNotFound
|
return nil, domain.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return dir, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *browser) GetSong(id string) (*Entry, error) {
|
func (b *browser) GetSong(id string) (*Entry, error) {
|
||||||
@@ -132,6 +136,13 @@ func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *Dir
|
|||||||
PlayCount: int32(al.PlayCount),
|
PlayCount: int32(al.PlayCount),
|
||||||
UserRating: al.Rating,
|
UserRating: al.Rating,
|
||||||
Starred: al.StarredAt,
|
Starred: al.StarredAt,
|
||||||
|
Artist: al.Artist,
|
||||||
|
ArtistId: al.ArtistId,
|
||||||
|
SongCount: al.SongCount,
|
||||||
|
Duration: al.Duration,
|
||||||
|
Created: al.CreatedAt,
|
||||||
|
Year: al.Year,
|
||||||
|
Genre: al.Genre,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.Entries = make(Entries, len(tracks))
|
dir.Entries = make(Entries, len(tracks))
|
||||||
|
|||||||
Reference in New Issue
Block a user