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];
+ }
}
}