Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
998f320e31
|
||
|
|
3836e97ccb
|
No files matched your search
@@ -320,44 +320,56 @@ func (c *Controller) ServeGetStarred(r *http.Request) *spec.Response {
|
||||
results := &spec.Starred{}
|
||||
|
||||
// "artists"
|
||||
rootQ := c.dbc.
|
||||
Select("id").
|
||||
Model(&db.Album{}).
|
||||
Where("parent_id IS NULL")
|
||||
if m := getMusicFolder(c, params); m != "" {
|
||||
rootQ = rootQ.Where("root_dir=?", m)
|
||||
}
|
||||
|
||||
var artists []*db.Album
|
||||
var artists []*db.Artist
|
||||
q := c.dbc.
|
||||
Where(`parent_id IN ?`, rootQ.SubQuery()).
|
||||
Joins("JOIN album_stars ON albums.id=album_stars.album_id").
|
||||
Where("album_stars.user_id=?", user.ID).
|
||||
Preload("AlbumStar", "user_id=?", user.ID).
|
||||
Preload("AlbumRating", "user_id=?", user.ID)
|
||||
Select("artists.*, count(albums.id) album_count").
|
||||
Joins("JOIN artist_stars ON artist_stars.artist_id=artists.id").
|
||||
Where("artist_stars.user_id=?", user.ID).
|
||||
Joins("JOIN artist_appearances ON artist_appearances.artist_id=artists.id").
|
||||
Joins("JOIN albums ON albums.id=artist_appearances.album_id").
|
||||
Order("artist_stars.star_date DESC").
|
||||
Preload("ArtistStar", "user_id=?", user.ID).
|
||||
Preload("ArtistRating", "user_id=?", user.ID).
|
||||
Preload("Info").
|
||||
Group("artists.id")
|
||||
if m := getMusicFolder(c, params); m != "" {
|
||||
q = q.Where("albums.root_dir=?", m)
|
||||
}
|
||||
if err := q.Find(&artists).Error; err != nil {
|
||||
return spec.NewError(0, "find artists: %v", err)
|
||||
}
|
||||
for _, a := range artists {
|
||||
results.Artists = append(results.Artists, spec.NewDirectoryByFolder(a, nil))
|
||||
results.Artists = append(results.Artists, spec.NewArtistByTags(a))
|
||||
}
|
||||
|
||||
// "albums"
|
||||
var albums []*db.Album
|
||||
q = c.dbc.
|
||||
Joins("JOIN album_artists ON album_artists.album_id=albums.id").
|
||||
Joins("JOIN album_stars ON albums.id=album_stars.album_id").
|
||||
Where("album_stars.user_id=?", user.ID).
|
||||
q = c.dbc.Where("parent_id IS NOT NULL").
|
||||
Joins("JOIN album_stars ON albums.id=album_stars.album_id AND album_stars.user_id=?", user.ID)
|
||||
q = q.Order("album_stars.star_date DESC")
|
||||
|
||||
q = q.
|
||||
Preload("AlbumStar", "user_id=?", user.ID).
|
||||
Preload("AlbumRating", "user_id=?", user.ID)
|
||||
|
||||
if m := getMusicFolder(c, params); m != "" {
|
||||
q = q.Where("root_dir=?", m)
|
||||
}
|
||||
|
||||
q.
|
||||
Select("albums.*, count(tracks.id) child_count, sum(tracks.length) duration").
|
||||
Joins("LEFT JOIN tracks ON tracks.album_id=albums.id").
|
||||
Group("albums.id").
|
||||
Joins("JOIN album_artists ON album_artists.album_id=albums.id").
|
||||
Preload("Parent").
|
||||
Preload("AlbumStar", "user_id=?", user.ID).
|
||||
Preload("AlbumRating", "user_id=?", user.ID)
|
||||
|
||||
if err := q.Find(&albums).Error; err != nil {
|
||||
return spec.NewError(0, "find albums: %v", err)
|
||||
}
|
||||
for _, a := range albums {
|
||||
results.Albums = append(results.Albums, spec.NewTCAlbumByFolder(a))
|
||||
results.Albums = append(results.Albums, spec.NewAlbumByFolder(a))
|
||||
}
|
||||
|
||||
// tracks
|
||||
|
||||
@@ -28,6 +28,7 @@ func (c *Controller) ServeGetArtists(r *http.Request) *spec.Response {
|
||||
q := c.dbc.
|
||||
Select("*, count(album_artists.album_id) album_count").
|
||||
Joins("JOIN album_artists ON album_artists.artist_id=artists.id").
|
||||
Joins("LEFT JOIN artist_stars ON artist_stars.artist_id=artists.id").
|
||||
Preload("ArtistStar", "user_id=?", user.ID).
|
||||
Preload("ArtistRating", "user_id=?", user.ID).
|
||||
Preload("Info").
|
||||
|
||||
@@ -6,14 +6,22 @@ import (
|
||||
"sort"
|
||||
|
||||
"go.senan.xyz/gonic/db"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
|
||||
)
|
||||
|
||||
func NewAlbumByFolder(f *db.Album) *Album {
|
||||
artist := ""
|
||||
var parentSID *specid.ID
|
||||
if f.Parent != nil {
|
||||
artist = f.Parent.RightPath
|
||||
parentSID = f.ParentSID()
|
||||
}
|
||||
|
||||
a := &Album{
|
||||
Artist: f.Parent.RightPath,
|
||||
Artist: artist,
|
||||
ID: f.SID(),
|
||||
IsDir: true,
|
||||
ParentID: f.ParentSID(),
|
||||
ParentID: parentSID,
|
||||
Album: f.RightPath,
|
||||
Name: f.RightPath,
|
||||
Title: f.RightPath,
|
||||
|
||||
@@ -442,8 +442,8 @@ type Bookmark struct {
|
||||
}
|
||||
|
||||
type Starred struct {
|
||||
Artists []*Directory `xml:"artist,omitempty" json:"artist,omitempty"`
|
||||
Albums []*TrackChild `xml:"album,omitempty" json:"album,omitempty"`
|
||||
Artists []*Artist `xml:"artist,omitempty" json:"artist,omitempty"`
|
||||
Albums []*Album `xml:"album,omitempty" json:"album,omitempty"`
|
||||
Tracks []*TrackChild `xml:"song,omitempty" json:"song,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user