Переглянути джерело

Simplify logic in ProviderManager.SaveImage

Bond_009 4 місяців тому
батько
коміт
9e869b4541
1 змінених файлів з 3 додано та 13 видалено
  1. 3 13
      MediaBrowser.Providers/Manager/ProviderManager.cs

+ 3 - 13
MediaBrowser.Providers/Manager/ProviderManager.cs

@@ -204,20 +204,10 @@ namespace MediaBrowser.Providers.Manager
                     {
                         contentType = MediaTypeNames.Image.Png;
                     }
-                    else
-                    {
-                        throw new HttpRequestException("Invalid image received: contentType not set.", null, response.StatusCode);
-                    }
-                }
-
-                // TVDb will sometimes serve a rubbish 404 html page with a 200 OK code, because reasons...
-                if (contentType.Equals(MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase))
-                {
-                    throw new HttpRequestException("Invalid image received.", null, HttpStatusCode.NotFound);
                 }
 
-                // some iptv/epg providers don't correctly report media type, extract from url if no extension found
-                if (string.IsNullOrWhiteSpace(MimeTypes.ToExtension(contentType)))
+                // some providers don't correctly report media type, extract from url if no extension found
+                if (contentType is null || contentType.Equals(MediaTypeNames.Application.Octet, StringComparison.OrdinalIgnoreCase))
                 {
                     // Strip query parameters from url to get actual path.
                     contentType = MimeTypes.GetMimeType(new Uri(url).GetLeftPart(UriPartial.Path));
@@ -225,7 +215,7 @@ namespace MediaBrowser.Providers.Manager
 
                 if (!contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
                 {
-                    throw new HttpRequestException($"Request returned {contentType} instead of an image type", null, HttpStatusCode.NotFound);
+                    throw new HttpRequestException($"Request returned '{contentType}' instead of an image type", null, HttpStatusCode.NotFound);
                 }
 
                 var responseBytes = await response.Content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(false);