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