mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 18:33:33 +00:00
improve similar items fallback, make ND album artist for song actually album artist, fix full screen race
This commit is contained in:
parent
2257e439a4
commit
14086ebc9c
15 changed files with 136 additions and 17 deletions
|
|
@ -47,10 +47,14 @@ import {
|
|||
genreListSortMap,
|
||||
ServerInfo,
|
||||
ServerInfoArgs,
|
||||
SimilarSongsArgs,
|
||||
Song,
|
||||
} from '../types';
|
||||
import { hasFeature } from '/@/renderer/api/utils';
|
||||
import { ServerFeature, ServerFeatures } from '/@/renderer/api/features-types';
|
||||
import { SubsonicExtensions } from '/@/renderer/api/subsonic/subsonic-types';
|
||||
import { NDSongListSort } from '/@/renderer/api/navidrome.types';
|
||||
import { ssNormalize } from '/@/renderer/api/subsonic/subsonic-normalize';
|
||||
|
||||
const authenticate = async (
|
||||
url: string,
|
||||
|
|
@ -545,6 +549,58 @@ const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
|
|||
return { features, id: apiClientProps.server?.id, version: ping.body.serverVersion! };
|
||||
};
|
||||
|
||||
const getSimilarSongs = async (args: SimilarSongsArgs): Promise<Song[]> => {
|
||||
const { apiClientProps, query } = args;
|
||||
|
||||
// Prefer getSimilarSongs (which queries last.fm) where available
|
||||
// otherwise find other tracks by the same album artist
|
||||
const res = await ssApiClient({
|
||||
...apiClientProps,
|
||||
silent: true,
|
||||
}).getSimilarSongs({
|
||||
query: {
|
||||
count: query.count,
|
||||
id: query.songId,
|
||||
},
|
||||
});
|
||||
|
||||
if (res.status === 200 && res.body.similarSongs?.song) {
|
||||
const similar = res.body.similarSongs.song.reduce<Song[]>((acc, song) => {
|
||||
if (song.id !== query.songId) {
|
||||
acc.push(ssNormalize.song(song, apiClientProps.server, ''));
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
if (similar.length > 0) {
|
||||
return similar;
|
||||
}
|
||||
}
|
||||
|
||||
const fallback = await ndApiClient(apiClientProps).getSongList({
|
||||
query: {
|
||||
_end: 50,
|
||||
_order: 'ASC',
|
||||
_sort: NDSongListSort.RANDOM,
|
||||
_start: 0,
|
||||
album_artist_id: query.albumArtistIds,
|
||||
},
|
||||
});
|
||||
|
||||
if (fallback.status !== 200) {
|
||||
throw new Error('Failed to get similar songs');
|
||||
}
|
||||
|
||||
return fallback.body.data.reduce<Song[]>((acc, song) => {
|
||||
if (song.id !== query.songId) {
|
||||
acc.push(ndNormalize.song(song, apiClientProps.server, ''));
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
};
|
||||
|
||||
export const ndController = {
|
||||
addToPlaylist,
|
||||
authenticate,
|
||||
|
|
@ -559,6 +615,7 @@ export const ndController = {
|
|||
getPlaylistList,
|
||||
getPlaylistSongList,
|
||||
getServerInfo,
|
||||
getSimilarSongs,
|
||||
getSongDetail,
|
||||
getSongList,
|
||||
getUserList,
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ const normalizeSong = (
|
|||
const imagePlaceholderUrl = null;
|
||||
return {
|
||||
album: item.album,
|
||||
albumArtists: [{ id: item.artistId, imageUrl: null, name: item.artist }],
|
||||
albumArtists: [{ id: item.albumArtistId, imageUrl: null, name: item.albumArtist }],
|
||||
albumId: item.albumId,
|
||||
artistName: item.artist,
|
||||
artists: [{ id: item.artistId, imageUrl: null, name: item.artist }],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue