Files
pgsql-jellyfin/MediaBrowser.Model/Extensions/EnumerableExtensions.cs
T
wjones af1152b001 Refactor: standardize namespace and using directive style
Refactored all C# test files to use explicit namespace declarations and moved all using directives inside the namespace block for consistency. Updated assembly info and cache files to reflect the new build. Adjusted MvcTestingAppManifest.json to use fully qualified assembly names. No functional changes; all updates are related to code style, organization, and project metadata.
2026-02-20 16:26:53 -05:00

60 lines
2.3 KiB
C#

// <copyright file="EnumerableExtensions.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace MediaBrowser.Model.Extensions;
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using MediaBrowser.Model.Providers;
/// <summary>
/// Extension methods for <see cref="IEnumerable{T}"/>.
/// </summary>
public static class EnumerableExtensions
{
/// <summary>
/// Orders <see cref="RemoteImageInfo"/> by requested language in descending order, prioritizing "en" over other non-matches.
/// </summary>
/// <param name="remoteImageInfos">The remote image infos.</param>
/// <param name="requestedLanguage">The requested language for the images.</param>
/// <returns>The ordered remote image infos.</returns>
public static IEnumerable<RemoteImageInfo> OrderByLanguageDescending(this IEnumerable<RemoteImageInfo> remoteImageInfos, string requestedLanguage)
{
if (string.IsNullOrWhiteSpace(requestedLanguage))
{
// Default to English if no requested language is specified.
requestedLanguage = "en";
}
return remoteImageInfos.OrderByDescending(i =>
{
// Image priority ordering:
// - Images that match the requested language
// - Images with no language
// - TODO: Images that match the original language
// - Images in English
// - Images that don't match the requested language
if (string.Equals(requestedLanguage, i.Language, StringComparison.OrdinalIgnoreCase))
{
return 4;
}
if (string.IsNullOrEmpty(i.Language))
{
return 3;
}
if (string.Equals(i.Language, "en", StringComparison.OrdinalIgnoreCase))
{
return 2;
}
return 0;
})
.ThenByDescending(i => Math.Round(i.CommunityRating ?? 0, 1) )
.ThenByDescending(i => i.VoteCount ?? 0);
}
}