Add Stars to the DB, including Artists! Only if DevUseFolderScanner is true
This commit is contained in:
+4
-2
@@ -81,7 +81,7 @@ func (c *AlbumListController) GetAlbumList2(w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
func (c *AlbumListController) GetStarred(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
albums, mediaFiles, err := c.listGen.GetAllStarred()
|
||||
artists, albums, mediaFiles, err := c.listGen.GetAllStarred()
|
||||
if err != nil {
|
||||
log.Error(r, "Error retrieving starred media", "error", err)
|
||||
return nil, NewError(responses.ErrorGeneric, "Internal Error")
|
||||
@@ -89,13 +89,14 @@ func (c *AlbumListController) GetStarred(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
response := NewResponse()
|
||||
response.Starred = &responses.Starred{}
|
||||
response.Starred.Artist = ToArtists(artists)
|
||||
response.Starred.Album = ToChildren(albums)
|
||||
response.Starred.Song = ToChildren(mediaFiles)
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *AlbumListController) GetStarred2(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
albums, mediaFiles, err := c.listGen.GetAllStarred()
|
||||
artists, albums, mediaFiles, err := c.listGen.GetAllStarred()
|
||||
if err != nil {
|
||||
log.Error(r, "Error retrieving starred media", "error", err)
|
||||
return nil, NewError(responses.ErrorGeneric, "Internal Error")
|
||||
@@ -103,6 +104,7 @@ func (c *AlbumListController) GetStarred2(w http.ResponseWriter, r *http.Request
|
||||
|
||||
response := NewResponse()
|
||||
response.Starred2 = &responses.Starred{}
|
||||
response.Starred2.Artist = ToArtists(artists)
|
||||
response.Starred2.Album = ToAlbums(albums)
|
||||
response.Starred2.Song = ToChildren(mediaFiles)
|
||||
return response, nil
|
||||
|
||||
@@ -145,6 +145,21 @@ func ToAlbum(entry engine.Entry) responses.Child {
|
||||
return album
|
||||
}
|
||||
|
||||
func ToArtists(entries engine.Entries) []responses.Artist {
|
||||
artists := make([]responses.Artist, len(entries))
|
||||
for i, entry := range entries {
|
||||
artists[i] = responses.Artist{
|
||||
Id: entry.Id,
|
||||
Name: entry.Title,
|
||||
AlbumCount: entry.AlbumCount,
|
||||
}
|
||||
if !entry.Starred.IsZero() {
|
||||
artists[i].Starred = &entry.Starred
|
||||
}
|
||||
}
|
||||
return artists
|
||||
}
|
||||
|
||||
func ToChildren(entries engine.Entries) []responses.Child {
|
||||
children := make([]responses.Child, len(entries))
|
||||
for i, entry := range entries {
|
||||
|
||||
@@ -50,12 +50,15 @@ func (c *MediaAnnotationController) SetRating(w http.ResponseWriter, r *http.Req
|
||||
func (c *MediaAnnotationController) getIds(r *http.Request) ([]string, error) {
|
||||
ids := ParamStrings(r, "id")
|
||||
albumIds := ParamStrings(r, "albumId")
|
||||
artistIds := ParamStrings(r, "artistId")
|
||||
|
||||
if len(ids) == 0 && len(albumIds) == 0 {
|
||||
if len(ids)+len(albumIds)+len(artistIds) == 0 {
|
||||
return nil, NewError(responses.ErrorMissingParameter, "Required id parameter is missing")
|
||||
}
|
||||
|
||||
return append(ids, albumIds...), nil
|
||||
ids = append(ids, albumIds...)
|
||||
ids = append(ids, artistIds...)
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (c *MediaAnnotationController) Star(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"status":"ok","version":"1.8.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa"}]}],"lastModified":"1","ignoredArticles":"A"}}
|
||||
{"status":"ok","version":"1.8.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa","starred":"2016-03-02T20:30:00Z"}]}],"lastModified":"1","ignoredArticles":"A"}}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><indexes lastModified="1" ignoredArticles="A"><index name="A"><artist id="111" name="aaa"></artist></index></indexes></subsonic-response>
|
||||
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.8.0"><indexes lastModified="1" ignoredArticles="A"><index name="A"><artist id="111" name="aaa" starred="2016-03-02T20:30:00Z"></artist></index></indexes></subsonic-response>
|
||||
|
||||
@@ -57,11 +57,11 @@ type MusicFolders struct {
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
/*
|
||||
<xs:attribute name="starred" type="xs:dateTime" use="optional"/> <!-- Added in 1.10.1 -->
|
||||
<xs:attribute name="userRating" type="sub:UserRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
<xs:attribute name="averageRating" type="sub:AverageRating" use="optional"/> <!-- Added in 1.13.0 -->
|
||||
*/
|
||||
|
||||
@@ -90,7 +90,8 @@ var _ = Describe("Responses", func() {
|
||||
Context("with data", func() {
|
||||
BeforeEach(func() {
|
||||
artists := make([]Artist, 1)
|
||||
artists[0] = Artist{Id: "111", Name: "aaa"}
|
||||
t := time.Date(2016, 03, 2, 20, 30, 0, 0, time.UTC)
|
||||
artists[0] = Artist{Id: "111", Name: "aaa", Starred: &t}
|
||||
index := make([]Index, 1)
|
||||
index[0] = Index{Name: "A", Artists: artists}
|
||||
response.Indexes.Index = index
|
||||
|
||||
+4
-4
@@ -70,10 +70,7 @@ func (c *SearchingController) Search2(w http.ResponseWriter, r *http.Request) (*
|
||||
|
||||
response := NewResponse()
|
||||
searchResult2 := &responses.SearchResult2{}
|
||||
searchResult2.Artist = make([]responses.Artist, len(as))
|
||||
for i, e := range as {
|
||||
searchResult2.Artist[i] = responses.Artist{Id: e.Id, Name: e.Title}
|
||||
}
|
||||
searchResult2.Artist = ToArtists(as)
|
||||
searchResult2.Album = ToChildren(als)
|
||||
searchResult2.Song = ToChildren(mfs)
|
||||
response.SearchResult2 = searchResult2
|
||||
@@ -97,6 +94,9 @@ func (c *SearchingController) Search3(w http.ResponseWriter, r *http.Request) (*
|
||||
CoverArt: e.CoverArt,
|
||||
AlbumCount: e.AlbumCount,
|
||||
}
|
||||
if !e.Starred.IsZero() {
|
||||
searchResult3.Artist[i].Starred = &e.Starred
|
||||
}
|
||||
}
|
||||
searchResult3.Album = ToAlbums(als)
|
||||
searchResult3.Song = ToChildren(mfs)
|
||||
|
||||
Reference in New Issue
Block a user