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"
|
2020-08-13 13:51:57 -08:00
|
|
|
"strconv"
|
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"
|
|
|
|
|
"github.com/navidrome/navidrome/utils"
|
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) {
|
|
|
|
|
mediaFolderList, _ := api.ds.MediaFolder(r.Context()).GetAll()
|
2016-03-20 09:14:04 -08:00
|
|
|
folders := make([]responses.MusicFolder, len(mediaFolderList))
|
|
|
|
|
for i, f := range mediaFolderList {
|
2020-05-09 18:29:02 -08:00
|
|
|
folders[i].Id = 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
|
|
|
}
|
|
|
|
|
|
2022-12-31 13:29:58 -09:00
|
|
|
func (api *Router) getArtistIndex(r *http.Request, mediaFolderId int, ifModifiedSince time.Time) (*responses.Indexes, error) {
|
|
|
|
|
ctx := r.Context()
|
2022-11-21 08:57:56 -09:00
|
|
|
folder, err := api.ds.MediaFolder(ctx).Get(int32(mediaFolderId))
|
2016-03-09 06:22:10 -09:00
|
|
|
if err != nil {
|
2020-08-13 13:51:57 -08:00
|
|
|
log.Error(ctx, "Error retrieving MediaFolder", "id", mediaFolderId, err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2016-03-09 06:22:10 -09:00
|
|
|
}
|
|
|
|
|
|
2022-11-21 08:57:56 -09:00
|
|
|
l, err := api.ds.Property(ctx).DefaultGet(model.PropLastScan+"-"+folder.Path, "-1")
|
2020-08-13 13:51:57 -08:00
|
|
|
if err != nil {
|
|
|
|
|
log.Error(ctx, "Error retrieving LastScan property", err)
|
2020-10-27 11:23:29 -08:00
|
|
|
return nil, err
|
2020-08-13 13:51:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var indexes model.ArtistIndexes
|
|
|
|
|
ms, _ := strconv.ParseInt(l, 10, 64)
|
|
|
|
|
lastModified := utils.ToTime(ms)
|
|
|
|
|
if lastModified.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,
|
2020-05-09 17:00:38 -08:00
|
|
|
LastModified: utils.ToMillis(lastModified),
|
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) {
|
2020-10-25 17:52:51 -08:00
|
|
|
musicFolderId := utils.ParamInt(r, "musicFolderId", 0)
|
2020-02-06 14:55:38 -09:00
|
|
|
ifModifiedSince := utils.ParamTime(r, "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) {
|
2020-10-25 17:52:51 -08:00
|
|
|
musicFolderId := utils.ParamInt(r, "musicFolderId", 0)
|
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) {
|
2020-02-06 14:55:38 -09:00
|
|
|
id := utils.ParamString(r, "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) {
|
2020-02-06 14:55:38 -09:00
|
|
|
id := utils.ParamString(r, "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) {
|
2020-02-06 14:55:38 -09:00
|
|
|
id := utils.ParamString(r, "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) {
|
|
|
|
|
id, err := requiredParamString(r, "id")
|
|
|
|
|
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) {
|
2020-02-06 14:55:38 -09:00
|
|
|
id := utils.ParamString(r, "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()
|
2020-10-27 11:23:29 -08:00
|
|
|
id, err := requiredParamString(r, "id")
|
2020-10-18 15:10:11 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
count := utils.ParamInt(r, "count", 20)
|
|
|
|
|
includeNotPresent := utils.ParamBool(r, "includeNotPresent", false)
|
|
|
|
|
|
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()
|
2020-10-27 11:23:29 -08:00
|
|
|
id, err := requiredParamString(r, "id")
|
2020-10-20 09:38:44 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2020-10-20 18:53:52 -08:00
|
|
|
count := utils.ParamInt(r, "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()
|
2020-10-27 11:23:29 -08:00
|
|
|
artist, err := requiredParamString(r, "artist")
|
2020-10-20 18:53:52 -08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
count := utils.ParamInt(r, "count", 50)
|
|
|
|
|
|
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 {
|
|
|
|
|
dir.Played = &artist.PlayDate
|
|
|
|
|
}
|
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 {
|
|
|
|
|
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 {
|
|
|
|
|
dir.Played = &album.PlayDate
|
|
|
|
|
}
|
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 {
|
|
|
|
|
dir.Starred = &album.StarredAt
|
|
|
|
|
}
|
|
|
|
|
|
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{}
|
2020-08-13 14:50:28 -08:00
|
|
|
dir.Id = album.ID
|
|
|
|
|
dir.Name = album.Name
|
|
|
|
|
dir.Artist = album.AlbumArtist
|
|
|
|
|
dir.ArtistId = album.AlbumArtistID
|
2022-12-19 09:59:24 -09:00
|
|
|
dir.CoverArt = album.CoverArtID().String()
|
2023-03-14 05:48:52 -08:00
|
|
|
dir.SongCount = int32(album.SongCount)
|
|
|
|
|
dir.Duration = int32(album.Duration)
|
2020-08-13 14:50:28 -08:00
|
|
|
dir.PlayCount = album.PlayCount
|
2022-11-02 07:20:51 -08:00
|
|
|
if album.PlayCount > 0 {
|
|
|
|
|
dir.Played = &album.PlayDate
|
|
|
|
|
}
|
2023-03-14 05:48:52 -08:00
|
|
|
dir.Year = int32(album.MaxYear)
|
2020-08-13 14:50:28 -08:00
|
|
|
dir.Genre = album.Genre
|
2023-11-18 10:40:00 -09:00
|
|
|
dir.Genres = itemGenresFromGenres(album.Genres)
|
2023-03-14 05:48:52 -08:00
|
|
|
dir.UserRating = int32(album.Rating)
|
2020-08-13 14:50:28 -08:00
|
|
|
if !album.CreatedAt.IsZero() {
|
|
|
|
|
dir.Created = &album.CreatedAt
|
2016-03-28 05:16:03 -08:00
|
|
|
}
|
2020-08-13 14:50:28 -08:00
|
|
|
if album.Starred {
|
|
|
|
|
dir.Starred = &album.StarredAt
|
2016-03-28 05:16:03 -08:00
|
|
|
}
|
2023-11-18 10:40:00 -09:00
|
|
|
dir.MusicBrainzId = album.MbzAlbumID
|
2020-08-13 18:11:18 -08:00
|
|
|
dir.Song = childrenFromMediaFiles(ctx, mfs)
|
2016-03-28 05:16:03 -08:00
|
|
|
return dir
|
|
|
|
|
}
|