Skip to content

🎧 Your Personal Streaming Service

getAlbum.view implemented

Deluan615dc862afad
diff --git a/api/browsing.go b/api/browsing.go
index 11c443d6e..e2bd9f060 100644
--- a/api/browsing.go
+++ b/api/browsing.go
@@ -111,6 +111,24 @@ func (c *BrowsingController) GetArtist() {
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() {
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 {
- dir := &responses.ArtistWithAlbumsID3{
- Id: d.Id,
- Name: d.Name,
- PlayCount: d.PlayCount,
- AlbumCount: d.AlbumCount,
- UserRating: d.UserRating,
- }
+ dir := &responses.ArtistWithAlbumsID3{}
+ dir.Id = d.Id
+ dir.Name = d.Name
+ dir.AlbumCount = d.AlbumCount
+ dir.CoverArt = d.CoverArt
if !d.Starred.IsZero() {
dir.Starred = &d.Starred
}
@@ -162,3 +178,26 @@ func (c *BrowsingController) buildArtist(d *engine.DirectoryInfo) *responses.Art
dir.Album = c.ToAlbums(d.Entries)
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
+}
diff --git a/api/responses/responses.go b/api/responses/responses.go
index b31ff8c9c..080ad1721 100644
--- a/api/responses/responses.go
+++ b/api/responses/responses.go
@@ -27,6 +27,7 @@ type Subsonic struct {
// ID3
Artist *Indexes `xml:"artists,omitempty" json:"artists,omitempty"`
ArtistWithAlbumsID3 *ArtistWithAlbumsID3 `xml:"artist,omitempty" json:"artist,omitempty"`
+ AlbumWithSongsID3 *AlbumWithSongsID3 `xml:"album,omitempty" json:"album,omitempty"`
}
type JsonWrapper struct {
@@ -136,14 +137,37 @@ type Directory struct {
*/
}
-type ArtistWithAlbumsID3 struct {
- Album []Child `xml:"album" json:"album,omitempty"`
+type ArtistID3 struct {
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"`
+ CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,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 {
diff --git a/conf/router.go b/conf/router.go
index 1126034f0..54bb94134 100644
--- a/conf/router.go
+++ b/conf/router.go
@@ -26,6 +26,7 @@ func mapEndpoints() {
beego.NSRouter("/getSong.view", &api.BrowsingController{}, "*:GetSong"),
beego.NSRouter("/getArtists.view", &api.BrowsingController{}, "*:GetArtists"),
beego.NSRouter("/getArtist.view", &api.BrowsingController{}, "*:GetArtist"),
+ beego.NSRouter("/getAlbum.view", &api.BrowsingController{}, "*:GetAlbum"),
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
diff --git a/engine/browser.go b/engine/browser.go
index faa8b49e3..8cd4ebd05 100644
--- a/engine/browser.go
+++ b/engine/browser.go
@@ -15,6 +15,7 @@ type Browser interface {
Indexes(ifModifiedSince time.Time) (domain.ArtistIndexes, time.Time, error)
Directory(id string) (*DirectoryInfo, error)
Artist(id string) (*DirectoryInfo, error)
+ Album(id string) (*DirectoryInfo, error)
GetSong(id string) (*Entry, error)
}
@@ -63,6 +64,13 @@ type DirectoryInfo struct {
UserRating int
AlbumCount int
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) {
@@ -74,29 +82,25 @@ func (b *browser) Artist(id string) (*DirectoryInfo, error) {
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) {
- var dir *DirectoryInfo
switch {
case b.isArtist(id):
- beego.Debug("Found Artist with id", id)
- a, albums, err := b.retrieveArtist(id)
- if err != nil {
- return nil, err
- }
- dir = b.buildArtistDir(a, albums)
+ return b.Artist(id)
case b.isAlbum(id):
- beego.Debug("Found Album with id", id)
- al, tracks, err := b.retrieveAlbum(id)
- if err != nil {
- return nil, err
- }
- dir = b.buildAlbumDir(al, tracks)
+ return b.Album(id)
default:
beego.Debug("Id", id, "not found")
return nil, domain.ErrNotFound
}
-
- return dir, nil
}
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),
UserRating: al.Rating,
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))