From 96cf13060d0421c38399fec4352d0b56bb90e8dc Mon Sep 17 00:00:00 2001 From: Max <@> Date: Tue, 19 Nov 2024 15:43:22 -0500 Subject: [PATCH 1/4] Extension lookup tv icons --- .../Manager/ProviderManager.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index e43da13504..37074eddc3 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -200,11 +200,25 @@ namespace MediaBrowser.Providers.Manager // TODO: Isolate this hack into the tvh plugin if (string.IsNullOrEmpty(contentType)) { + // First, check for imagecache special case if (url.Contains("/imagecache/", StringComparison.OrdinalIgnoreCase)) { - contentType = MediaTypeNames.Image.Png; + contentType = "image/png"; + return; } - else + + // Deduce content type from file extension + var fileExtension = Path.GetExtension(url)?.ToLowerInvariant(); + contentType = fileExtension switch + { + ".jpg" or ".jpeg" => "image/jpeg", + ".png" => "image/png", + ".gif" => "image/gif", + ".webp" => "image/webp", + _ => null + }; + + if (string.IsNullOrEmpty(contentType)) { throw new HttpRequestException("Invalid image received: contentType not set.", null, response.StatusCode); } From 1ba0b887036458c9dbd53c45389691a5c06b9026 Mon Sep 17 00:00:00 2001 From: Max <@> Date: Tue, 19 Nov 2024 21:28:15 -0500 Subject: [PATCH 2/4] Use .net constants --- MediaBrowser.Providers/Manager/ProviderManager.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 37074eddc3..a6f98840a8 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -203,7 +203,7 @@ namespace MediaBrowser.Providers.Manager // First, check for imagecache special case if (url.Contains("/imagecache/", StringComparison.OrdinalIgnoreCase)) { - contentType = "image/png"; + contentType = MediaTypeNames.Image.Png; return; } @@ -211,9 +211,9 @@ namespace MediaBrowser.Providers.Manager var fileExtension = Path.GetExtension(url)?.ToLowerInvariant(); contentType = fileExtension switch { - ".jpg" or ".jpeg" => "image/jpeg", - ".png" => "image/png", - ".gif" => "image/gif", + ".jpg" or ".jpeg" => MediaTypeNames.Image.Jpeg, + ".png" => MediaTypeNames.Image.Png, + ".gif" => MediaTypeNames.Image.Gif, ".webp" => "image/webp", _ => null }; From 630de12e5e486a71d5bf449636bb9129f9eecc98 Mon Sep 17 00:00:00 2001 From: Max <@> Date: Wed, 4 Dec 2024 10:08:41 -0500 Subject: [PATCH 3/4] Apply review changes --- MediaBrowser.Providers/Manager/ProviderManager.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index a6f98840a8..62a74f076e 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -208,15 +208,8 @@ namespace MediaBrowser.Providers.Manager } // Deduce content type from file extension - var fileExtension = Path.GetExtension(url)?.ToLowerInvariant(); - contentType = fileExtension switch - { - ".jpg" or ".jpeg" => MediaTypeNames.Image.Jpeg, - ".png" => MediaTypeNames.Image.Png, - ".gif" => MediaTypeNames.Image.Gif, - ".webp" => "image/webp", - _ => null - }; + var fileExtension = MimeTypes.GetMimeType(new Uri(url).GetLeftPart(UriPartial.Path)); + contentType = fileExtension; if (string.IsNullOrEmpty(contentType)) { From 43fff5799bd61c6ae3053444f75ca61b14b0a031 Mon Sep 17 00:00:00 2001 From: Max <@> Date: Thu, 5 Dec 2024 17:02:37 -0500 Subject: [PATCH 4/4] Fix code --- MediaBrowser.Providers/Manager/ProviderManager.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 62a74f076e..010e9c3b63 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -200,17 +200,18 @@ namespace MediaBrowser.Providers.Manager // TODO: Isolate this hack into the tvh plugin if (string.IsNullOrEmpty(contentType)) { - // First, check for imagecache special case + // Special case for imagecache if (url.Contains("/imagecache/", StringComparison.OrdinalIgnoreCase)) { contentType = MediaTypeNames.Image.Png; - return; + } + else + { + // Deduce content type from file extension + contentType = MimeTypes.GetMimeType(new Uri(url).GetLeftPart(UriPartial.Path)); } - // Deduce content type from file extension - var fileExtension = MimeTypes.GetMimeType(new Uri(url).GetLeftPart(UriPartial.Path)); - contentType = fileExtension; - + // Throw if we still can't determine the content type if (string.IsNullOrEmpty(contentType)) { throw new HttpRequestException("Invalid image received: contentType not set.", null, response.StatusCode);