[bodge]: deal with Jellyfin returning dupliate tracks for album query

This commit is contained in:
Kendall Garner 2024-04-13 16:28:36 -07:00
parent 729538d885
commit 19a88fea86
No known key found for this signature in database
GPG key ID: 18D2767419676C87

View file

@ -445,8 +445,26 @@ const getSongList = async (args: SongListArgs): Promise<SongListResponse> => {
throw new Error('Failed to get song list');
}
let items: z.infer<typeof jfType._response.song>[];
// Jellyfin Bodge because of code from https://github.com/jellyfin/jellyfin/blob/c566ccb63bf61f9c36743ddb2108a57c65a2519b/Emby.Server.Implementations/Data/SqliteItemRepository.cs#L3622
// If the Album ID filter is passed, Jellyfin will search for
// 1. the matching album id
// 2. An album with the name of the album.
// It is this second condition causing issues,
if (query.albumIds) {
const albumIdSet = new Set(query.albumIds);
items = res.body.Items.filter((item) => albumIdSet.has(item.AlbumId));
if (items.length < res.body.Items.length) {
res.body.TotalRecordCount -= res.body.Items.length - items.length;
}
} else {
items = res.body.Items;
}
return {
items: res.body.Items.map((item) =>
items: items.map((item) =>
jfNormalize.song(item, apiClientProps.server, '', query.imageSize),
),
startIndex: query.startIndex,