diff options
Diffstat (limited to 'MediaBrowser.Controller')
| -rw-r--r-- | MediaBrowser.Controller/LiveTv/ISchedulesDirectService.cs | 37 | ||||
| -rw-r--r-- | MediaBrowser.Controller/LiveTv/ImageDownloadFailureAction.cs | 17 |
2 files changed, 47 insertions, 7 deletions
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 +} |
