mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Added getSong.view
This commit is contained in:
parent
06828d8738
commit
ee8e9864ea
4 changed files with 32 additions and 2 deletions
|
@ -64,8 +64,6 @@ func (c *BrowsingController) GetIndexes() {
|
||||||
func (c *BrowsingController) GetMusicDirectory() {
|
func (c *BrowsingController) GetMusicDirectory() {
|
||||||
id := c.RequiredParamString("id", "id parameter required")
|
id := c.RequiredParamString("id", "id parameter required")
|
||||||
|
|
||||||
response := c.NewEmpty()
|
|
||||||
|
|
||||||
dir, err := c.browser.Directory(id)
|
dir, err := c.browser.Directory(id)
|
||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
|
@ -76,8 +74,27 @@ func (c *BrowsingController) GetMusicDirectory() {
|
||||||
c.SendError(responses.ErrorGeneric, "Internal Error")
|
c.SendError(responses.ErrorGeneric, "Internal Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response := c.NewEmpty()
|
||||||
response.Directory = c.buildDirectory(dir)
|
response.Directory = c.buildDirectory(dir)
|
||||||
|
c.SendResponse(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BrowsingController) GetSong() {
|
||||||
|
id := c.RequiredParamString("id", "id parameter required")
|
||||||
|
|
||||||
|
song, err := c.browser.GetSong(id)
|
||||||
|
switch {
|
||||||
|
case err == domain.ErrNotFound:
|
||||||
|
beego.Error("Requested Id", id, "not found:", err)
|
||||||
|
c.SendError(responses.ErrorDataNotFound, "Directory not found")
|
||||||
|
case err != nil:
|
||||||
|
beego.Error(err)
|
||||||
|
c.SendError(responses.ErrorGeneric, "Internal Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
response := c.NewEmpty()
|
||||||
|
child := c.ToChild(*song)
|
||||||
|
response.Song = &child
|
||||||
c.SendResponse(response)
|
c.SendResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ type Subsonic struct {
|
||||||
SearchResult2 *SearchResult2 `xml:"searchResult2,omitempty" json:"searchResult2,omitempty"`
|
SearchResult2 *SearchResult2 `xml:"searchResult2,omitempty" json:"searchResult2,omitempty"`
|
||||||
Starred *Starred `xml:"starred,omitempty" json:"starred,omitempty"`
|
Starred *Starred `xml:"starred,omitempty" json:"starred,omitempty"`
|
||||||
NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`
|
NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`
|
||||||
|
Song *Child `xml:"song,omitempty" json:"song,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonWrapper struct {
|
type JsonWrapper struct {
|
||||||
|
|
|
@ -23,6 +23,7 @@ func mapEndpoints() {
|
||||||
beego.NSRouter("/getMusicFolders.view", &api.BrowsingController{}, "*:GetMusicFolders"),
|
beego.NSRouter("/getMusicFolders.view", &api.BrowsingController{}, "*:GetMusicFolders"),
|
||||||
beego.NSRouter("/getIndexes.view", &api.BrowsingController{}, "*:GetIndexes"),
|
beego.NSRouter("/getIndexes.view", &api.BrowsingController{}, "*:GetIndexes"),
|
||||||
beego.NSRouter("/getMusicDirectory.view", &api.BrowsingController{}, "*:GetMusicDirectory"),
|
beego.NSRouter("/getMusicDirectory.view", &api.BrowsingController{}, "*:GetMusicDirectory"),
|
||||||
|
beego.NSRouter("/getSong.view", &api.BrowsingController{}, "*:GetSong"),
|
||||||
|
|
||||||
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
beego.NSRouter("/search2.view", &api.SearchingController{}, "*:Search2"),
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ type Browser interface {
|
||||||
MediaFolders() (domain.MediaFolders, error)
|
MediaFolders() (domain.MediaFolders, error)
|
||||||
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)
|
||||||
|
GetSong(id string) (*Entry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBrowser(pr PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository,
|
func NewBrowser(pr PropertyRepository, fr domain.MediaFolderRepository, ir domain.ArtistIndexRepository,
|
||||||
|
@ -87,6 +88,16 @@ func (b *browser) Directory(id string) (*DirectoryInfo, error) {
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *browser) GetSong(id string) (*Entry, error) {
|
||||||
|
mf, err := b.mfileRepo.Get(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := FromMediaFile(mf)
|
||||||
|
return &entry, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
|
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}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue