From e4b095a7663ef0c41d1d3198ef03192533fa1039 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Mon, 13 Jun 2022 16:27:16 -0600 Subject: [PATCH] Merge pull request #7894 from crobibero/search-hints (cherry picked from commit 0f75f177361906626e658da86d63583d5111f006) Signed-off-by: crobibero --- Jellyfin.Api/Controllers/SearchController.cs | 3 ++- src/Jellyfin.Extensions/ReadOnlyListExtension.cs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Api/Controllers/SearchController.cs b/Jellyfin.Api/Controllers/SearchController.cs index 6ffedccbd4..07e113ad3e 100644 --- a/Jellyfin.Api/Controllers/SearchController.cs +++ b/Jellyfin.Api/Controllers/SearchController.cs @@ -6,6 +6,7 @@ using System.Linq; using Jellyfin.Api.Constants; using Jellyfin.Api.ModelBinders; using Jellyfin.Data.Enums; +using Jellyfin.Extensions; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; @@ -187,7 +188,7 @@ namespace Jellyfin.Api.Controllers result.AlbumArtist = album.AlbumArtist; break; case Audio song: - result.AlbumArtist = song.AlbumArtists?[0]; + result.AlbumArtist = song.AlbumArtists?.FirstOrDefault(); result.Artists = song.Artists; MusicAlbum musicAlbum = song.AlbumEntity; diff --git a/src/Jellyfin.Extensions/ReadOnlyListExtension.cs b/src/Jellyfin.Extensions/ReadOnlyListExtension.cs index 7785cfb495..ba99bb534d 100644 --- a/src/Jellyfin.Extensions/ReadOnlyListExtension.cs +++ b/src/Jellyfin.Extensions/ReadOnlyListExtension.cs @@ -57,5 +57,21 @@ namespace Jellyfin.Extensions return -1; } + + /// + /// Get the first or default item from a list. + /// + /// The source list. + /// The type of item. + /// The first item or default if list is empty. + public static T? FirstOrDefault(this IReadOnlyList? source) + { + if (source is null || source.Count == 0) + { + return default; + } + + return source[0]; + } } }