🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
search3.view implemented
Deluan231945499732
diff --git a/api/responses/responses.go b/api/responses/responses.goindex f1ecaf358..734ef09f6 100644--- a/api/responses/responses.go+++ b/api/responses/responses.go@@ -20,6 +20,7 @@ type Subsonic struct {Playlists *Playlists `xml:"playlists,omitempty" json:"playlists,omitempty"`Playlist *PlaylistWithSongs `xml:"playlist,omitempty" json:"playlist,omitempty"`SearchResult2 *SearchResult2 `xml:"searchResult2,omitempty" json:"searchResult2,omitempty"`+ SearchResult3 *SearchResult3 `xml:"searchResult3,omitempty" json:"searchResult3,omitempty"`Starred *Starred `xml:"starred,omitempty" json:"starred,omitempty"`Starred2 *Starred `xml:"starred2,omitempty" json:"starred2,omitempty"`NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`@@ -210,6 +211,12 @@ type SearchResult2 struct {Song []Child `xml:"song" json:"song,omitempty"`}+type SearchResult3 struct {+ Artist []ArtistID3 `xml:"artist" json:"artist,omitempty"`+ Album []Child `xml:"album" json:"album,omitempty"`+ Song []Child `xml:"song" json:"song,omitempty"`+}+type Starred struct {Artist []Artist `xml:"artist" json:"artist,omitempty"`Album []Child `xml:"album" json:"album,omitempty"`diff --git a/api/searching.go b/api/searching.goindex c7eec77a2..d1cb6d147 100644--- a/api/searching.go+++ b/api/searching.go@@ -11,36 +11,51 @@ import (type SearchingController struct {BaseAPIController- search engine.Search+ search engine.Search+ query string+ artistCount int+ artistOffset int+ albumCount int+ albumOffset int+ songCount int+ songOffset int}func (c *SearchingController) Prepare() {utils.ResolveDependencies(&c.search)}-func (c *SearchingController) Search2() {- query := c.RequiredParamString("query", "Parameter query required")- artistCount := c.ParamInt("artistCount", 20)- artistOffset := c.ParamInt("artistOffset", 0)- albumCount := c.ParamInt("albumCount", 20)- albumOffset := c.ParamInt("albumOffset", 0)- songCount := c.ParamInt("songCount", 20)- songOffset := c.ParamInt("songOffset", 0)-- as, err := c.search.SearchArtist(query, artistOffset, artistCount)+func (c *SearchingController) getParams() {+ c.query = c.RequiredParamString("query", "Parameter query required")+ c.artistCount = c.ParamInt("artistCount", 20)+ c.artistOffset = c.ParamInt("artistOffset", 0)+ c.albumCount = c.ParamInt("albumCount", 20)+ c.albumOffset = c.ParamInt("albumOffset", 0)+ c.songCount = c.ParamInt("songCount", 20)+ c.songOffset = c.ParamInt("songOffset", 0)+}++func (c *SearchingController) searchAll() (engine.Entries, engine.Entries, engine.Entries) {+ as, err := c.search.SearchArtist(c.query, c.artistOffset, c.artistCount)if err != nil {beego.Error("Error searching for Artists:", err)}- als, err := c.search.SearchAlbum(query, albumOffset, albumCount)+ als, err := c.search.SearchAlbum(c.query, c.albumOffset, c.albumCount)if err != nil {beego.Error("Error searching for Albums:", err)}- mfs, err := c.search.SearchSong(query, songOffset, songCount)+ mfs, err := c.search.SearchSong(c.query, c.songOffset, c.songCount)if err != nil {beego.Error("Error searching for MediaFiles:", err)}- beego.Debug(fmt.Sprintf("Searching for [%s] resulted in %d songs, %d albums and %d artists", query, len(mfs), len(als), len(as)))+ beego.Debug(fmt.Sprintf("Searching for [%s] resulted in %d songs, %d albums and %d artists", c.query, len(mfs), len(als), len(as)))+ return mfs, als, as+}++func (c *SearchingController) Search2() {+ c.getParams()+ mfs, als, as := c.searchAll()response := c.NewEmpty()searchResult2 := &responses.SearchResult2{}@@ -53,3 +68,24 @@ func (c *SearchingController) Search2() {response.SearchResult2 = searchResult2c.SendResponse(response)}++func (c *SearchingController) Search3() {+ c.getParams()+ mfs, als, as := c.searchAll()++ response := c.NewEmpty()+ searchResult3 := &responses.SearchResult3{}+ searchResult3.Artist = make([]responses.ArtistID3, len(as))+ for i, e := range as {+ searchResult3.Artist[i] = responses.ArtistID3{+ Id: e.Id,+ Name: e.Title,+ CoverArt: e.CoverArt,+ AlbumCount: e.AlbumCount,+ }+ }+ searchResult3.Album = c.ToAlbums(als)+ searchResult3.Song = c.ToChildren(mfs)+ response.SearchResult3 = searchResult3+ c.SendResponse(response)+}diff --git a/conf/router.go b/conf/router.goindex 51da7cded..2aa6d3850 100644--- a/conf/router.go+++ b/conf/router.go@@ -29,6 +29,7 @@ func mapEndpoints() {beego.NSRouter("/getAlbum.view", &api.BrowsingController{}, "*:GetAlbum"),beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),+ beego.NSRouter("/search3.view", &api.SearchingController{}, "*:Search3"),beego.NSRouter("/getCoverArt.view", &api.MediaRetrievalController{}, "*:GetCoverArt"),beego.NSRouter("/getAvatar.view", &api.MediaRetrievalController{}, "*:GetAvatar"),diff --git a/engine/common.go b/engine/common.goindex 733657263..7e4873917 100644--- a/engine/common.go+++ b/engine/common.go@@ -38,10 +38,20 @@ type Entry struct {MinutesAgo intPlayerId intPlayerName string+ AlbumCount int}type Entries []Entry+func FromArtist(ar *domain.Artist) Entry {+ e := Entry{}+ e.Id = ar.Id+ e.Title = ar.Name+ e.AlbumCount = ar.AlbumCount+ e.IsDir = true+ return e+}+func FromAlbum(al *domain.Album) Entry {e := Entry{}e.Id = al.Iddiff --git a/engine/search.go b/engine/search.goindex fee807a1b..e4a41cae8 100644--- a/engine/search.go+++ b/engine/search.go@@ -99,7 +99,7 @@ func (s *search) SearchArtist(q string, offset int, size int) (Entries, error) {return nil, err}if err == nil {- res = append(res, Entry{Id: a.Id, Title: a.Name, IsDir: true})+ res = append(res, FromArtist(a))}}return res, nil