mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-18 21:07:44 +03:00
search3.view implemented
This commit is contained in:
parent
a562bfd17e
commit
2319454997
@ -20,6 +20,7 @@ type Subsonic struct {
|
|||||||
Playlists *Playlists `xml:"playlists,omitempty" json:"playlists,omitempty"`
|
Playlists *Playlists `xml:"playlists,omitempty" json:"playlists,omitempty"`
|
||||||
Playlist *PlaylistWithSongs `xml:"playlist,omitempty" json:"playlist,omitempty"`
|
Playlist *PlaylistWithSongs `xml:"playlist,omitempty" json:"playlist,omitempty"`
|
||||||
SearchResult2 *SearchResult2 `xml:"searchResult2,omitempty" json:"searchResult2,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"`
|
Starred *Starred `xml:"starred,omitempty" json:"starred,omitempty"`
|
||||||
Starred2 *Starred `xml:"starred2,omitempty" json:"starred2,omitempty"`
|
Starred2 *Starred `xml:"starred2,omitempty" json:"starred2,omitempty"`
|
||||||
NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`
|
NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`
|
||||||
@ -210,6 +211,12 @@ type SearchResult2 struct {
|
|||||||
Song []Child `xml:"song" json:"song,omitempty"`
|
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 {
|
type Starred struct {
|
||||||
Artist []Artist `xml:"artist" json:"artist,omitempty"`
|
Artist []Artist `xml:"artist" json:"artist,omitempty"`
|
||||||
Album []Child `xml:"album" json:"album,omitempty"`
|
Album []Child `xml:"album" json:"album,omitempty"`
|
||||||
|
@ -11,36 +11,51 @@ import (
|
|||||||
|
|
||||||
type SearchingController struct {
|
type SearchingController struct {
|
||||||
BaseAPIController
|
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() {
|
func (c *SearchingController) Prepare() {
|
||||||
utils.ResolveDependencies(&c.search)
|
utils.ResolveDependencies(&c.search)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SearchingController) Search2() {
|
func (c *SearchingController) getParams() {
|
||||||
query := c.RequiredParamString("query", "Parameter query required")
|
c.query = c.RequiredParamString("query", "Parameter query required")
|
||||||
artistCount := c.ParamInt("artistCount", 20)
|
c.artistCount = c.ParamInt("artistCount", 20)
|
||||||
artistOffset := c.ParamInt("artistOffset", 0)
|
c.artistOffset = c.ParamInt("artistOffset", 0)
|
||||||
albumCount := c.ParamInt("albumCount", 20)
|
c.albumCount = c.ParamInt("albumCount", 20)
|
||||||
albumOffset := c.ParamInt("albumOffset", 0)
|
c.albumOffset = c.ParamInt("albumOffset", 0)
|
||||||
songCount := c.ParamInt("songCount", 20)
|
c.songCount = c.ParamInt("songCount", 20)
|
||||||
songOffset := c.ParamInt("songOffset", 0)
|
c.songOffset = c.ParamInt("songOffset", 0)
|
||||||
|
}
|
||||||
|
|
||||||
as, err := c.search.SearchArtist(query, artistOffset, artistCount)
|
func (c *SearchingController) searchAll() (engine.Entries, engine.Entries, engine.Entries) {
|
||||||
|
as, err := c.search.SearchArtist(c.query, c.artistOffset, c.artistCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("Error searching for Artists:", err)
|
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 {
|
if err != nil {
|
||||||
beego.Error("Error searching for Albums:", err)
|
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 {
|
if err != nil {
|
||||||
beego.Error("Error searching for MediaFiles:", err)
|
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()
|
response := c.NewEmpty()
|
||||||
searchResult2 := &responses.SearchResult2{}
|
searchResult2 := &responses.SearchResult2{}
|
||||||
@ -53,3 +68,24 @@ func (c *SearchingController) Search2() {
|
|||||||
response.SearchResult2 = searchResult2
|
response.SearchResult2 = searchResult2
|
||||||
c.SendResponse(response)
|
c.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)
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ func mapEndpoints() {
|
|||||||
beego.NSRouter("/getAlbum.view", &api.BrowsingController{}, "*:GetAlbum"),
|
beego.NSRouter("/getAlbum.view", &api.BrowsingController{}, "*:GetAlbum"),
|
||||||
|
|
||||||
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
||||||
|
beego.NSRouter("/search3.view", &api.SearchingController{}, "*:Search3"),
|
||||||
|
|
||||||
beego.NSRouter("/getCoverArt.view", &api.MediaRetrievalController{}, "*:GetCoverArt"),
|
beego.NSRouter("/getCoverArt.view", &api.MediaRetrievalController{}, "*:GetCoverArt"),
|
||||||
beego.NSRouter("/getAvatar.view", &api.MediaRetrievalController{}, "*:GetAvatar"),
|
beego.NSRouter("/getAvatar.view", &api.MediaRetrievalController{}, "*:GetAvatar"),
|
||||||
|
@ -38,10 +38,20 @@ type Entry struct {
|
|||||||
MinutesAgo int
|
MinutesAgo int
|
||||||
PlayerId int
|
PlayerId int
|
||||||
PlayerName string
|
PlayerName string
|
||||||
|
AlbumCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Entries []Entry
|
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 {
|
func FromAlbum(al *domain.Album) Entry {
|
||||||
e := Entry{}
|
e := Entry{}
|
||||||
e.Id = al.Id
|
e.Id = al.Id
|
||||||
|
@ -99,7 +99,7 @@ func (s *search) SearchArtist(q string, offset int, size int) (Entries, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
res = append(res, Entry{Id: a.Id, Title: a.Name, IsDir: true})
|
res = append(res, FromArtist(a))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user