diff options
Diffstat (limited to 'MediaBrowser.Controller')
8 files changed, 125 insertions, 17 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index a1e955f33f..2e3665f528 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1045,20 +1045,41 @@ namespace MediaBrowser.Controller.Entities } } + return ModifySortChunks(ApplySortCharacterRules(sortable, configuration)); + } + + private static string ApplySortCharacterRules(string name, ServerConfiguration configuration) + { foreach (var removeChar in configuration.SortRemoveCharacters) { - sortable = sortable.Replace(removeChar, string.Empty, StringComparison.Ordinal); + name = name.Replace(removeChar, string.Empty, StringComparison.Ordinal); } foreach (var replaceChar in configuration.SortReplaceCharacters) { - sortable = sortable.Replace(replaceChar, " ", StringComparison.Ordinal); + name = name.Replace(replaceChar, " ", StringComparison.Ordinal); } - return ModifySortChunks(sortable); + return name; } - internal static string ModifySortChunks(ReadOnlySpan<char> name) + /// <summary> + /// Normalizes a user-provided name filter value to match against <see cref="SortName"/>. + /// Applies the same character removal/replacement, zero-padding, diacritics removal, and transliteration + /// as sort name generation, but not <c>SortRemoveWords</c> since stripping articles from a prefix is unsafe. + /// </summary> + /// <param name="input">The raw filter value from the API.</param> + /// <returns>The normalized value suitable for comparison against SortName. Casing is preserved; callers requiring case-sensitive matching must handle it themselves.</returns> + public static string NormalizeSortNameFilter(string input) + => ModifySortChunks(ApplySortCharacterRules(input, ConfigurationManager.Configuration)); + + /// <summary> + /// Processes a name by zero-padding numeric chunks to 10 digits for natural sort order, + /// removing diacritics, and transliterating non-ASCII characters. + /// </summary> + /// <param name="name">The input name to process.</param> + /// <returns>The processed string with padded numeric chunks.</returns> + public static string ModifySortChunks(ReadOnlySpan<char> name) { static void AppendChunk(StringBuilder builder, bool isDigitChunk, ReadOnlySpan<char> chunk) { diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 626bc0d5a1..f325778f8b 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -1182,17 +1182,22 @@ namespace MediaBrowser.Controller.Entities { if (!string.IsNullOrWhiteSpace(query.NameStartsWith)) { - items = items.Where(i => i.SortName.StartsWith(query.NameStartsWith, StringComparison.OrdinalIgnoreCase)); + var paddedPrefix = BaseItem.NormalizeSortNameFilter(query.NameStartsWith); + items = items.Where(i => + i.SortName.StartsWith(paddedPrefix, StringComparison.OrdinalIgnoreCase) + || i.SortName.TrimStart('0').StartsWith(query.NameStartsWith, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrWhiteSpace(query.NameStartsWithOrGreater)) { - items = items.Where(i => string.Compare(i.SortName, query.NameStartsWithOrGreater, StringComparison.OrdinalIgnoreCase) >= 0); + var paddedValue = BaseItem.NormalizeSortNameFilter(query.NameStartsWithOrGreater); + items = items.Where(i => string.Compare(i.SortName, paddedValue, StringComparison.OrdinalIgnoreCase) >= 0); } if (!string.IsNullOrWhiteSpace(query.NameLessThan)) { - items = items.Where(i => string.Compare(i.SortName, query.NameLessThan, StringComparison.OrdinalIgnoreCase) < 0); + var paddedValue = BaseItem.NormalizeSortNameFilter(query.NameLessThan); + items = items.Where(i => string.Compare(i.SortName, paddedValue, StringComparison.OrdinalIgnoreCase) < 0); } return items; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 82256cd964..f88759a5d8 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -531,18 +531,22 @@ namespace MediaBrowser.Controller.Entities IUserDataManager userDataManager, ILibraryManager libraryManager) { - if (!string.IsNullOrEmpty(query.NameStartsWith) && !item.SortName.StartsWith(query.NameStartsWith, StringComparison.InvariantCultureIgnoreCase)) + if (!string.IsNullOrEmpty(query.NameStartsWith) + && !item.SortName.StartsWith(BaseItem.NormalizeSortNameFilter(query.NameStartsWith), StringComparison.InvariantCultureIgnoreCase) + && !item.SortName.TrimStart('0').StartsWith(query.NameStartsWith, StringComparison.InvariantCultureIgnoreCase)) { return false; } #pragma warning disable CA1309 // Use ordinal string comparison - if (!string.IsNullOrEmpty(query.NameStartsWithOrGreater) && string.Compare(query.NameStartsWithOrGreater, item.SortName, StringComparison.InvariantCultureIgnoreCase) == 1) + if (!string.IsNullOrEmpty(query.NameStartsWithOrGreater) + && string.Compare(BaseItem.NormalizeSortNameFilter(query.NameStartsWithOrGreater), item.SortName, StringComparison.InvariantCultureIgnoreCase) == 1) { return false; } - if (!string.IsNullOrEmpty(query.NameLessThan) && string.Compare(query.NameLessThan, item.SortName, StringComparison.InvariantCultureIgnoreCase) != 1) + if (!string.IsNullOrEmpty(query.NameLessThan) + && string.Compare(BaseItem.NormalizeSortNameFilter(query.NameLessThan), item.SortName, StringComparison.InvariantCultureIgnoreCase) != 1) #pragma warning restore CA1309 // Use ordinal string comparison { return false; diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index ae15c75350..8d00858b37 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -851,6 +851,20 @@ namespace MediaBrowser.Controller.Library QueryFiltersLegacy GetQueryFiltersLegacy(InternalItemsQuery query); /// <summary> + /// Gets the distinct, sorted production years of the matching items. + /// </summary> + /// <param name="query">The query filter.</param> + /// <returns>The production years.</returns> + IReadOnlyList<int> GetYears(InternalItemsQuery query); + + /// <summary> + /// Gets the distinct, sorted official ratings of the matching items. + /// </summary> + /// <param name="query">The query filter.</param> + /// <returns>The official ratings.</returns> + IReadOnlyList<string> GetOfficialRatings(InternalItemsQuery query); + + /// <summary> /// Gets a list of all distinct tags of the matching items. /// </summary> /// <param name="query">The query filter.</param> diff --git a/MediaBrowser.Controller/LiveTv/ISchedulesDirectService.cs b/MediaBrowser.Controller/LiveTv/ISchedulesDirectService.cs index 6953650952..a0df011811 100644 --- a/MediaBrowser.Controller/LiveTv/ISchedulesDirectService.cs +++ b/MediaBrowser.Controller/LiveTv/ISchedulesDirectService.cs @@ -1,6 +1,8 @@ using System.IO; +using System.Net; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; namespace MediaBrowser.Controller.LiveTv; @@ -17,15 +19,36 @@ public interface ISchedulesDirectService Task<Stream> GetAvailableCountries(CancellationToken cancellationToken); /// <summary> - /// Gets a value indicating whether the Schedules Direct daily image download limit is currently active. + /// Gets a value indicating whether an image may be downloaded from the given url. /// </summary> - /// <returns><c>true</c> if the image limit has been hit and has not yet reset; otherwise <c>false</c>.</returns> - bool IsImageDailyLimitActive(); + /// <param name="imageUrl">The image url.</param> + /// <returns><c>false</c> for a Schedules Direct url while the daily image limit is active; otherwise <c>true</c>.</returns> + bool CanDownloadImage(string imageUrl); /// <summary> - /// Gets a value indicating whether the Schedules Direct service is available. - /// Returns <c>false</c> if a permanent account error has occurred or a transient backoff is active. + /// Reports a successful image download, so that an unexplained failure streak is reset. /// </summary> - /// <returns><c>true</c> if the service can accept requests; otherwise <c>false</c>.</returns> - bool IsServiceAvailable(); + /// <param name="imageUrl">The image url that was downloaded.</param> + void ReportImageDownloadSuccess(string imageUrl); + + /// <summary> + /// Reports a failed image download. Schedules Direct answers an exhausted image quota with + /// an HTTP 200 JSON error body rather than a failure status, so the body is what decides + /// whether image acquisition has to stop. + /// </summary> + /// <param name="imageUrl">The image url that failed.</param> + /// <param name="statusCode">The HTTP status code of the failure, if any.</param> + /// <param name="responseBody">The body of the failed response, if it was readable.</param> + /// <returns>What the caller must do with the image.</returns> + ImageDownloadFailureAction ReportImageDownloadFailure(string imageUrl, HttpStatusCode? statusCode, string? responseBody); + + /// <summary> + /// Downloads a remote image unless Schedules Direct has blocked it, and reports the outcome. + /// Schedules Direct counts every image request, so downloads outside the guide refresh go through here. + /// </summary> + /// <param name="item">The item the image belongs to.</param> + /// <param name="image">The remote image.</param> + /// <param name="imageIndex">The image index.</param> + /// <returns>The local image, or <c>null</c> when the download is blocked.</returns> + Task<ItemImageInfo?> ConvertImageToLocal(BaseItem item, ItemImageInfo image, int imageIndex); } diff --git a/MediaBrowser.Controller/LiveTv/ImageDownloadFailureAction.cs b/MediaBrowser.Controller/LiveTv/ImageDownloadFailureAction.cs new file mode 100644 index 0000000000..78a1e554b6 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/ImageDownloadFailureAction.cs @@ -0,0 +1,17 @@ +namespace MediaBrowser.Controller.LiveTv; + +/// <summary> +/// What the caller must do with an image after a failed download. +/// </summary> +public enum ImageDownloadFailureAction +{ + /// <summary> + /// Keep the image; the download may succeed on a later attempt. + /// </summary> + None = 0, + + /// <summary> + /// Drop the image. The url is permanently invalid and re-requesting it gets the account blocked. + /// </summary> + RemoveImage = 1 +} diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index ebfa78176a..f3382b2d51 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -3116,6 +3116,16 @@ namespace MediaBrowser.Controller.MediaEncoding } seekParam += string.Format(CultureInfo.InvariantCulture, "-ss {0}", _mediaEncoder.GetTimeParameter(seekTick)); + + // Retain audio from the preceding keyframe to match copied video's start time. + if (isHlsRemuxing + && state.AudioStream is not null + && !string.IsNullOrEmpty(state.OutputAudioCodec) + && !IsCopyCodec(state.OutputAudioCodec) + && !string.Equals(state.InputContainer, "wtv", StringComparison.OrdinalIgnoreCase)) + { + seekParam += " -noaccurate_seek"; + } } return seekParam; diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs index 3cf06b897c..69c74d3757 100644 --- a/MediaBrowser.Controller/Persistence/IItemRepository.cs +++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs @@ -149,6 +149,20 @@ public interface IItemRepository QueryFiltersLegacy GetQueryFiltersLegacy(InternalItemsQuery filter); /// <summary> + /// Gets the distinct, sorted production years of the matching items. + /// </summary> + /// <param name="filter">The query filter.</param> + /// <returns>The production years.</returns> + IReadOnlyList<int> GetYears(InternalItemsQuery filter); + + /// <summary> + /// Gets the distinct, sorted official ratings of the matching items. + /// </summary> + /// <param name="filter">The query filter.</param> + /// <returns>The official ratings.</returns> + IReadOnlyList<string> GetOfficialRatings(InternalItemsQuery filter); + + /// <summary> /// Gets whether all children of the requested item have been played. /// </summary> /// <param name="user">The user to check against.</param> |
