Proxy images to fix broken meta-data
This commit is contained in:
@@ -156,26 +156,46 @@ public class SRFImageProvider : IRemoteImageProvider, IHasOrder
|
||||
/// <inheritdoc />
|
||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogDebug("Fetching image from URL: {Url}", url);
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
|
||||
|
||||
// Create request with proper headers - SRF CDN requires User-Agent
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, new Uri(url));
|
||||
request.Headers.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
|
||||
request.Headers.Accept.ParseAdd("image/*");
|
||||
request.Headers.Accept.ParseAdd("image/jpeg, image/png, image/webp, image/*;q=0.8");
|
||||
|
||||
var response = await httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Fix Content-Type if it's binary/octet-stream - SRF CDN returns wrong content type
|
||||
var originalContentType = response.Content.Headers.ContentType?.MediaType;
|
||||
_logger.LogDebug(
|
||||
"Image response status: {StatusCode}, Content-Type: {ContentType}, Content-Length: {Length}",
|
||||
response.StatusCode,
|
||||
originalContentType ?? "null",
|
||||
response.Content.Headers.ContentLength);
|
||||
|
||||
// Fix Content-Type if it's not a proper image type - SRF CDN often returns wrong content type
|
||||
// Jellyfin needs correct Content-Type to process images
|
||||
if (response.IsSuccessStatusCode &&
|
||||
response.Content.Headers.ContentType?.MediaType == "binary/octet-stream")
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
// Determine correct content type from URL extension
|
||||
var contentType = GetContentTypeFromUrl(url);
|
||||
if (!string.IsNullOrEmpty(contentType))
|
||||
var needsContentTypeFix = string.IsNullOrEmpty(originalContentType) ||
|
||||
originalContentType == "binary/octet-stream" ||
|
||||
originalContentType == "application/octet-stream" ||
|
||||
!originalContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
if (needsContentTypeFix)
|
||||
{
|
||||
_logger.LogDebug("Fixing Content-Type from binary/octet-stream to {ContentType} for {Url}", contentType, url);
|
||||
response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
||||
// Determine correct content type from URL extension or default to JPEG
|
||||
var contentType = GetContentTypeFromUrl(url);
|
||||
if (!string.IsNullOrEmpty(contentType))
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Fixing Content-Type from '{OriginalType}' to '{NewType}' for {Url}",
|
||||
originalContentType ?? "null",
|
||||
contentType,
|
||||
url);
|
||||
response.Content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user