2020-01-19 14:21:44 -09:00
|
|
|
package subsonic
|
2016-03-02 16:00:55 -09:00
|
|
|
|
|
|
|
|
import (
|
2020-03-16 08:56:15 -08:00
|
|
|
"context"
|
2022-09-30 14:54:25 -08:00
|
|
|
"errors"
|
2020-01-07 10:56:26 -09:00
|
|
|
"net/http"
|
2016-03-11 16:49:01 -09:00
|
|
|
"time"
|
|
|
|
|
|
2020-01-23 15:44:08 -09:00
|
|
|
"github.com/navidrome/navidrome/conf"
|
|
|
|
|
"github.com/navidrome/navidrome/log"
|
|
|
|
|
"github.com/navidrome/navidrome/model"
|
2023-01-22 08:25:35 -09:00
|
|
|
"github.com/navidrome/navidrome/server/public"
|
2021-07-16 13:39:00 -08:00
|
|
|
"github.com/navidrome/navidrome/server/subsonic/filter"
|
2020-01-23 15:44:08 -09:00
|
|
|
"github.com/navidrome/navidrome/server/subsonic/responses"
|
2023-12-21 13:41:09 -09:00
|
|
|
"github.com/navidrome/navidrome/utils/req"
|
2016-03-02 16:00:55 -09:00
|
|
|
)
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetMusicFolders(r *http.Request) (*responses.Subsonic, error) {
|
2024-05-07 07:28:44 -08:00
|
|
|
libraries, _ := api.ds.Library(r.Context()).GetAll()
|
|
|
|
|
folders := make([]responses.MusicFolder, len(libraries))
|
|
|
|
|
for i, f := range libraries {
|
2024-05-07 07:29:45 -08:00
|
|
|
folders[i].Id = int32(f.ID)
|
2016-03-09 06:22:10 -09:00
|
|
|
folders[i].Name = f.Name
|
|
|
|
|
}
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2016-03-09 06:22:10 -09:00
|
|
|
response.MusicFolders = &responses.MusicFolders{Folders: folders}
|
2020-01-07 10:56:26 -09:00
|
|
|
return response, nil
|
2016-03-09 06:22:10 -09:00
|
|
|
}
|
|
|
|
|
|
2024-05-07 07:28:44 -08:00
|
|
|
func (api *Router) getArtistIndex(r *http.Request, libId int, ifModifiedSince time.Time) (*responses.Indexes, error) {
|
2022-12-31 13:29:58 -09:00
|
|
|
ctx := r.Context()
|
2024-05-07 07:52:13 -08:00
|
|
|
lib, err := api.ds.Library(ctx).Get(libId)
|
2016-03-09 06:22:10 -09:00
|
|
|
if err != nil {
|
2024-05-07 07:28:44 -08:00
|
|
|
log.Error(ctx, "Error retrieving Library", "id", libId, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2016-03-09 06:22:10 -09:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 13:51:57 -08:00
|
|
|
var indexes model.ArtistIndexes
|
2024-05-07 07:52:13 -08:00
|
|
|
if lib.LastScanAt.After(ifModifiedSince) {
|
2022-11-21 08:57:56 -09:00
|
|
|
indexes, err = api.ds.Artist(ctx).GetIndex()
|
2020-08-13 13:51:57 -08:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error(ctx, "Error retrieving Indexes", err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2020-08-13 13:51:57 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 10:56:26 -09:00
|
|
|
res := &responses.Indexes{
|
2020-01-23 21:29:31 -09:00
|
|
|
IgnoredArticles: conf.Server.IgnoredArticles,
|
2024-05-07 07:52:13 -08:00
|
|
|
LastModified: lib.LastScanAt.UnixMilli(),
|
2016-03-09 06:22:10 -09:00
|
|
|
}
|
|
|
|
|
|
2016-03-20 09:08:24 -08:00
|
|
|
res.Index = make([]responses.Index, len(indexes))
|
|
|
|
|
for i, idx := range indexes {
|
2020-01-10 15:41:35 -09:00
|
|
|
res.Index[i].Name = idx.ID
|
2022-12-31 13:29:58 -09:00
|
|
|
res.Index[i].Artists = toArtists(r, idx.Artists)
|
2016-03-09 06:22:10 -09:00
|
|
|
}
|
2020-01-07 10:56:26 -09:00
|
|
|
return res, nil
|
2016-03-27 16:35:10 -08:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetIndexes(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
2024-05-07 07:29:45 -08:00
|
|
|
musicFolderId := p.IntOr("musicFolderId", 1)
|
2023-12-21 13:41:09 -09:00
|
|
|
ifModifiedSince := p.TimeOr("ifModifiedSince", time.Time{})
|
2016-03-27 16:35:10 -08:00
|
|
|
|
2022-12-31 13:29:58 -09:00
|
|
|
res, err := api.getArtistIndex(r, musicFolderId, ifModifiedSince)
|
2020-01-07 10:56:26 -09:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-03-09 06:22:10 -09:00
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-01-07 10:56:26 -09:00
|
|
|
response.Indexes = res
|
|
|
|
|
return response, nil
|
2016-03-09 06:22:10 -09:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetArtists(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
2024-05-07 07:29:45 -08:00
|
|
|
musicFolderId := p.IntOr("musicFolderId", 1)
|
2022-12-31 13:29:58 -09:00
|
|
|
res, err := api.getArtistIndex(r, musicFolderId, time.Time{})
|
2020-01-07 10:56:26 -09:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2016-03-27 16:35:10 -08:00
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-01-07 10:56:26 -09:00
|
|
|
response.Artist = res
|
|
|
|
|
return response, nil
|
2016-03-27 16:35:10 -08:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetMusicDirectory(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, _ := p.String("id")
|
2020-08-13 17:52:44 -08:00
|
|
|
ctx := r.Context()
|
|
|
|
|
|
2022-12-28 08:32:46 -09:00
|
|
|
entity, err := model.GetEntityByID(ctx, api.ds, id)
|
2022-09-30 14:54:25 -08:00
|
|
|
if errors.Is(err, model.ErrNotFound) {
|
2020-01-09 19:33:01 -09:00
|
|
|
log.Error(r, "Requested ID not found ", "id", id)
|
2020-08-13 18:11:18 -08:00
|
|
|
return nil, newError(responses.ErrorDataNotFound, "Directory not found")
|
2022-09-30 14:54:25 -08:00
|
|
|
}
|
|
|
|
|
if err != nil {
|
2020-01-08 16:45:07 -09:00
|
|
|
log.Error(err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2016-03-02 16:00:55 -09:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 17:52:44 -08:00
|
|
|
var dir *responses.Directory
|
|
|
|
|
|
|
|
|
|
switch v := entity.(type) {
|
|
|
|
|
case *model.Artist:
|
2022-11-21 08:57:56 -09:00
|
|
|
dir, err = api.buildArtistDirectory(ctx, v)
|
2020-08-13 17:52:44 -08:00
|
|
|
case *model.Album:
|
2022-11-21 08:57:56 -09:00
|
|
|
dir, err = api.buildAlbumDirectory(ctx, v)
|
2020-08-13 17:52:44 -08:00
|
|
|
default:
|
|
|
|
|
log.Error(r, "Requested ID of invalid type", "id", id, "entity", v)
|
2020-08-13 18:11:18 -08:00
|
|
|
return nil, newError(responses.ErrorDataNotFound, "Directory not found")
|
2020-08-13 17:52:44 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error(err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2020-08-13 17:52:44 -08:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-08-13 17:52:44 -08:00
|
|
|
response.Directory = dir
|
2020-01-07 10:56:26 -09:00
|
|
|
return response, nil
|
2016-03-24 20:04:22 -08:00
|
|
|
}
|
2016-03-08 04:48:47 -09:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetArtist(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, _ := p.String("id")
|
2020-08-13 14:37:54 -08:00
|
|
|
ctx := r.Context()
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
artist, err := api.ds.Artist(ctx).Get(id)
|
2022-09-30 14:54:25 -08:00
|
|
|
if errors.Is(err, model.ErrNotFound) {
|
2020-08-13 14:37:54 -08:00
|
|
|
log.Error(ctx, "Requested ArtistID not found ", "id", id)
|
2020-08-13 18:11:18 -08:00
|
|
|
return nil, newError(responses.ErrorDataNotFound, "Artist not found")
|
2022-09-30 14:54:25 -08:00
|
|
|
}
|
|
|
|
|
if err != nil {
|
2020-08-13 14:37:54 -08:00
|
|
|
log.Error(ctx, "Error retrieving artist", "id", id, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2020-08-13 14:37:54 -08:00
|
|
|
}
|
|
|
|
|
|
2023-01-18 10:20:06 -09:00
|
|
|
response := newResponse()
|
|
|
|
|
response.ArtistWithAlbumsID3, err = api.buildArtist(r, artist)
|
2020-08-13 14:37:54 -08:00
|
|
|
if err != nil {
|
2023-01-18 10:20:06 -09:00
|
|
|
log.Error(ctx, "Error retrieving albums by artist", "id", artist.ID, "name", artist.Name, err)
|
2016-03-27 17:27:45 -08:00
|
|
|
}
|
2023-01-18 10:20:06 -09:00
|
|
|
return response, err
|
2016-03-27 17:27:45 -08:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetAlbum(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, _ := p.String("id")
|
2023-01-17 16:22:54 -09:00
|
|
|
|
2020-08-13 14:50:28 -08:00
|
|
|
ctx := r.Context()
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
album, err := api.ds.Album(ctx).Get(id)
|
2022-09-30 14:54:25 -08:00
|
|
|
if errors.Is(err, model.ErrNotFound) {
|
2020-08-13 14:50:28 -08:00
|
|
|
log.Error(ctx, "Requested AlbumID not found ", "id", id)
|
2020-08-13 18:11:18 -08:00
|
|
|
return nil, newError(responses.ErrorDataNotFound, "Album not found")
|
2022-09-30 14:54:25 -08:00
|
|
|
}
|
|
|
|
|
if err != nil {
|
2020-08-13 14:50:28 -08:00
|
|
|
log.Error(ctx, "Error retrieving album", "id", id, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2020-08-13 14:50:28 -08:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
mfs, err := api.ds.MediaFile(ctx).GetAll(filter.SongsByAlbum(id))
|
2020-08-13 14:50:28 -08:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error(ctx, "Error retrieving tracks from album", "id", id, "name", album.Name, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2016-03-28 05:16:03 -08:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2022-11-21 08:57:56 -09:00
|
|
|
response.AlbumWithSongsID3 = api.buildAlbum(ctx, album, mfs)
|
2020-01-07 10:56:26 -09:00
|
|
|
return response, nil
|
2016-03-28 05:16:03 -08:00
|
|
|
}
|
|
|
|
|
|
2023-01-17 16:22:54 -09:00
|
|
|
func (api *Router) GetAlbumInfo(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, err := p.String("id")
|
2023-01-17 16:22:54 -09:00
|
|
|
ctx := r.Context()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
album, err := api.externalMetadata.UpdateAlbumInfo(ctx, id)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response := newResponse()
|
|
|
|
|
response.AlbumInfo = &responses.AlbumInfo{}
|
|
|
|
|
response.AlbumInfo.Notes = album.Description
|
2023-02-08 10:27:26 -09:00
|
|
|
response.AlbumInfo.SmallImageUrl = public.ImageURL(r, album.CoverArtID(), 150)
|
|
|
|
|
response.AlbumInfo.MediumImageUrl = public.ImageURL(r, album.CoverArtID(), 300)
|
|
|
|
|
response.AlbumInfo.LargeImageUrl = public.ImageURL(r, album.CoverArtID(), 600)
|
|
|
|
|
|
2023-01-17 16:22:54 -09:00
|
|
|
response.AlbumInfo.LastFmUrl = album.ExternalUrl
|
|
|
|
|
response.AlbumInfo.MusicBrainzID = album.MbzAlbumID
|
|
|
|
|
|
|
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetSong(r *http.Request) (*responses.Subsonic, error) {
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, _ := p.String("id")
|
2020-08-13 17:57:35 -08:00
|
|
|
ctx := r.Context()
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
mf, err := api.ds.MediaFile(ctx).Get(id)
|
2022-09-30 14:54:25 -08:00
|
|
|
if errors.Is(err, model.ErrNotFound) {
|
2020-08-13 17:57:35 -08:00
|
|
|
log.Error(r, "Requested MediaFileID not found ", "id", id)
|
2020-08-13 18:11:18 -08:00
|
|
|
return nil, newError(responses.ErrorDataNotFound, "Song not found")
|
2022-09-30 14:54:25 -08:00
|
|
|
}
|
|
|
|
|
if err != nil {
|
2020-08-13 17:57:35 -08:00
|
|
|
log.Error(r, "Error retrieving MediaFile", "id", id, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2016-03-24 20:04:22 -08:00
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
|
|
|
|
child := childFromMediaFile(ctx, *mf)
|
2016-03-24 20:04:22 -08:00
|
|
|
response.Song = &child
|
2020-01-07 10:56:26 -09:00
|
|
|
return response, nil
|
2016-03-02 16:00:55 -09:00
|
|
|
}
|
2016-03-02 16:50:16 -09:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetGenres(r *http.Request) (*responses.Subsonic, error) {
|
2020-08-13 18:07:50 -08:00
|
|
|
ctx := r.Context()
|
2022-11-21 08:57:56 -09:00
|
|
|
genres, err := api.ds.Genre(ctx).GetAll(model.QueryOptions{Sort: "song_count, album_count, name desc", Order: "desc"})
|
2020-01-15 13:49:09 -09:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error(r, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2020-01-15 13:49:09 -09:00
|
|
|
}
|
2020-08-13 18:07:50 -08:00
|
|
|
for i, g := range genres {
|
2021-07-19 11:30:22 -08:00
|
|
|
if g.Name == "" {
|
2020-08-13 18:07:50 -08:00
|
|
|
genres[i].Name = "<Empty>"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-15 13:49:09 -09:00
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
|
|
|
|
response.Genres = toGenres(genres)
|
2020-01-15 13:49:09 -09:00
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetArtistInfo(r *http.Request) (*responses.Subsonic, error) {
|
2020-10-18 15:10:11 -08:00
|
|
|
ctx := r.Context()
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, err := p.String("id")
|
2020-10-18 15:10:11 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2023-12-21 13:41:09 -09:00
|
|
|
count := p.IntOr("count", 20)
|
|
|
|
|
includeNotPresent := p.BoolOr("includeNotPresent", false)
|
2020-10-18 15:10:11 -08:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
artist, err := api.externalMetadata.UpdateArtistInfo(ctx, id, count, includeNotPresent)
|
2020-10-18 15:10:11 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-02-09 15:42:37 -09:00
|
|
|
response.ArtistInfo = &responses.ArtistInfo{}
|
2020-10-30 12:08:43 -08:00
|
|
|
response.ArtistInfo.Biography = artist.Biography
|
2023-02-08 10:27:26 -09:00
|
|
|
response.ArtistInfo.SmallImageUrl = public.ImageURL(r, artist.CoverArtID(), 150)
|
|
|
|
|
response.ArtistInfo.MediumImageUrl = public.ImageURL(r, artist.CoverArtID(), 300)
|
|
|
|
|
response.ArtistInfo.LargeImageUrl = public.ImageURL(r, artist.CoverArtID(), 600)
|
2020-10-30 12:08:43 -08:00
|
|
|
response.ArtistInfo.LastFmUrl = artist.ExternalUrl
|
|
|
|
|
response.ArtistInfo.MusicBrainzID = artist.MbzArtistID
|
|
|
|
|
for _, s := range artist.SimilarArtists {
|
2022-12-31 13:29:58 -09:00
|
|
|
similar := toArtist(r, s)
|
2020-10-18 15:10:11 -08:00
|
|
|
response.ArtistInfo.SimilarArtist = append(response.ArtistInfo.SimilarArtist, similar)
|
|
|
|
|
}
|
2020-02-09 15:42:37 -09:00
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetArtistInfo2(r *http.Request) (*responses.Subsonic, error) {
|
|
|
|
|
info, err := api.GetArtistInfo(r)
|
2020-10-18 15:10:11 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-02-09 15:42:37 -09:00
|
|
|
response.ArtistInfo2 = &responses.ArtistInfo2{}
|
2020-10-18 15:10:11 -08:00
|
|
|
response.ArtistInfo2.ArtistInfoBase = info.ArtistInfo.ArtistInfoBase
|
|
|
|
|
for _, s := range info.ArtistInfo.SimilarArtist {
|
|
|
|
|
similar := responses.ArtistID3{}
|
|
|
|
|
similar.Id = s.Id
|
|
|
|
|
similar.Name = s.Name
|
|
|
|
|
similar.AlbumCount = s.AlbumCount
|
|
|
|
|
similar.Starred = s.Starred
|
2021-11-23 17:50:57 -09:00
|
|
|
similar.UserRating = s.UserRating
|
2022-12-31 13:29:58 -09:00
|
|
|
similar.CoverArt = s.CoverArt
|
|
|
|
|
similar.ArtistImageUrl = s.ArtistImageUrl
|
2020-10-18 15:10:11 -08:00
|
|
|
response.ArtistInfo2.SimilarArtist = append(response.ArtistInfo2.SimilarArtist, similar)
|
|
|
|
|
}
|
2020-02-09 15:42:37 -09:00
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetSimilarSongs(r *http.Request) (*responses.Subsonic, error) {
|
2020-10-20 09:38:44 -08:00
|
|
|
ctx := r.Context()
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
id, err := p.String("id")
|
2020-10-20 09:38:44 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2023-12-21 13:41:09 -09:00
|
|
|
count := p.IntOr("count", 50)
|
2020-10-20 09:38:44 -08:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
songs, err := api.externalMetadata.SimilarSongs(ctx, id, count)
|
2020-10-20 09:38:44 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response := newResponse()
|
|
|
|
|
response.SimilarSongs = &responses.SimilarSongs{
|
|
|
|
|
Song: childrenFromMediaFiles(ctx, songs),
|
|
|
|
|
}
|
|
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetSimilarSongs2(r *http.Request) (*responses.Subsonic, error) {
|
|
|
|
|
res, err := api.GetSimilarSongs(r)
|
2020-10-20 09:38:44 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response := newResponse()
|
|
|
|
|
response.SimilarSongs2 = &responses.SimilarSongs2{
|
2020-10-20 12:00:29 -08:00
|
|
|
Song: res.SimilarSongs.Song,
|
2020-10-20 09:38:44 -08:00
|
|
|
}
|
|
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) GetTopSongs(r *http.Request) (*responses.Subsonic, error) {
|
2020-10-20 18:53:52 -08:00
|
|
|
ctx := r.Context()
|
2023-12-21 13:41:09 -09:00
|
|
|
p := req.Params(r)
|
|
|
|
|
artist, err := p.String("artist")
|
2020-10-20 18:53:52 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2023-12-21 13:41:09 -09:00
|
|
|
count := p.IntOr("count", 50)
|
2020-10-20 18:53:52 -08:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
songs, err := api.externalMetadata.TopSongs(ctx, artist, count)
|
2020-10-20 18:53:52 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
response := newResponse()
|
2020-10-20 18:53:52 -08:00
|
|
|
response.TopSongs = &responses.TopSongs{
|
|
|
|
|
Song: childrenFromMediaFiles(ctx, songs),
|
|
|
|
|
}
|
2020-08-05 09:48:50 -08:00
|
|
|
return response, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) buildArtistDirectory(ctx context.Context, artist *model.Artist) (*responses.Directory, error) {
|
2020-08-13 17:52:44 -08:00
|
|
|
dir := &responses.Directory{}
|
|
|
|
|
dir.Id = artist.ID
|
|
|
|
|
dir.Name = artist.Name
|
|
|
|
|
dir.PlayCount = artist.PlayCount
|
2022-11-02 07:20:51 -08:00
|
|
|
if artist.PlayCount > 0 {
|
2023-12-09 09:52:17 -09:00
|
|
|
dir.Played = artist.PlayDate
|
2022-11-02 07:20:51 -08:00
|
|
|
}
|
2023-03-14 05:48:52 -08:00
|
|
|
dir.AlbumCount = int32(artist.AlbumCount)
|
|
|
|
|
dir.UserRating = int32(artist.Rating)
|
2020-08-13 17:52:44 -08:00
|
|
|
if artist.Starred {
|
2023-12-09 09:52:17 -09:00
|
|
|
dir.Starred = artist.StarredAt
|
2016-03-21 05:35:18 -08:00
|
|
|
}
|
2020-08-13 17:52:44 -08:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
albums, err := api.ds.Album(ctx).GetAllWithoutGenres(filter.AlbumsByArtistID(artist.ID))
|
2020-08-13 17:52:44 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2016-03-21 05:35:18 -08:00
|
|
|
}
|
2016-03-08 04:48:47 -09:00
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
dir.Child = childrenFromAlbums(ctx, albums)
|
2020-08-13 17:52:44 -08:00
|
|
|
return dir, nil
|
2016-03-03 05:50:50 -09:00
|
|
|
}
|
2016-03-27 17:27:45 -08:00
|
|
|
|
2023-01-18 10:20:06 -09:00
|
|
|
func (api *Router) buildArtist(r *http.Request, artist *model.Artist) (*responses.ArtistWithAlbumsID3, error) {
|
|
|
|
|
ctx := r.Context()
|
2020-10-30 12:08:43 -08:00
|
|
|
a := &responses.ArtistWithAlbumsID3{}
|
2022-12-31 13:29:58 -09:00
|
|
|
a.ArtistID3 = toArtistID3(r, *artist)
|
2023-01-18 10:20:06 -09:00
|
|
|
|
|
|
|
|
albums, err := api.ds.Album(ctx).GetAllWithoutGenres(filter.AlbumsByArtistID(artist.ID))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-31 13:29:58 -09:00
|
|
|
a.Album = childrenFromAlbums(r.Context(), albums)
|
2023-01-18 10:20:06 -09:00
|
|
|
return a, nil
|
2016-03-27 17:27:45 -08:00
|
|
|
}
|
2016-03-28 05:16:03 -08:00
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) buildAlbumDirectory(ctx context.Context, album *model.Album) (*responses.Directory, error) {
|
2020-08-13 17:52:44 -08:00
|
|
|
dir := &responses.Directory{}
|
|
|
|
|
dir.Id = album.ID
|
|
|
|
|
dir.Name = album.Name
|
|
|
|
|
dir.Parent = album.AlbumArtistID
|
|
|
|
|
dir.PlayCount = album.PlayCount
|
2022-11-02 07:20:51 -08:00
|
|
|
if album.PlayCount > 0 {
|
2023-12-09 09:52:17 -09:00
|
|
|
dir.Played = album.PlayDate
|
2022-11-02 07:20:51 -08:00
|
|
|
}
|
2023-03-14 05:48:52 -08:00
|
|
|
dir.UserRating = int32(album.Rating)
|
|
|
|
|
dir.SongCount = int32(album.SongCount)
|
2022-12-19 09:59:24 -09:00
|
|
|
dir.CoverArt = album.CoverArtID().String()
|
2020-08-13 17:52:44 -08:00
|
|
|
if album.Starred {
|
2023-12-09 09:52:17 -09:00
|
|
|
dir.Starred = album.StarredAt
|
2020-08-13 17:52:44 -08:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
mfs, err := api.ds.MediaFile(ctx).GetAll(filter.SongsByAlbum(album.ID))
|
2020-08-13 17:52:44 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 18:11:18 -08:00
|
|
|
dir.Child = childrenFromMediaFiles(ctx, mfs)
|
2020-08-13 17:52:44 -08:00
|
|
|
return dir, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
func (api *Router) buildAlbum(ctx context.Context, album *model.Album, mfs model.MediaFiles) *responses.AlbumWithSongsID3 {
|
2016-03-28 05:16:03 -08:00
|
|
|
dir := &responses.AlbumWithSongsID3{}
|
2023-12-09 10:11:07 -09:00
|
|
|
dir.AlbumID3 = buildAlbumID3(ctx, *album)
|
2020-08-13 18:11:18 -08:00
|
|
|
dir.Song = childrenFromMediaFiles(ctx, mfs)
|
2016-03-28 05:16:03 -08:00
|
|
|
return dir
|
|
|
|
|
}
|