Use Uri.TryCreate and ImageType helper method

pull/5321/head
David 3 years ago
parent 16694b0cfc
commit 6f898145af

@ -803,25 +803,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers
break;
}
ImageType imageType = artType switch
{
"banner" => ImageType.Banner,
"clearlogo" => ImageType.Logo,
"discart" => ImageType.Disc,
"landscape" => ImageType.Thumb,
"clearart" => ImageType.Art,
// unknown type (including "poster") --> primary
_ => ImageType.Primary,
};
Uri uri;
try
{
uri = new Uri(val);
}
catch (UriFormatException ex)
ImageType imageType = GetImageType(artType);
if (!Uri.TryCreate(val, UriKind.Absolute, out var uri) || uri == null)
{
Logger.LogError(ex, "Image location {Path} specified in nfo file for {ItemName} is not a valid URL or file path.", val, item.Name);
Logger.LogError("Image location {Path} specified in nfo file for {ItemName} is not a valid URL or file path.", val, item.Name);
break;
}
@ -1256,5 +1242,24 @@ namespace MediaBrowser.XbmcMetadata.Parsers
return string.IsNullOrWhiteSpace(value) ? Array.Empty<string>() : value.Split(separator, StringSplitOptions.RemoveEmptyEntries);
}
/// <summary>
/// Parses the ImageType from the nfo aspect property.
/// </summary>
/// <param name="aspect">The nfo aspect property.</param>
/// <returns>The image type.</returns>
private static ImageType GetImageType(string aspect)
{
return aspect switch
{
"banner" => ImageType.Banner,
"clearlogo" => ImageType.Logo,
"discart" => ImageType.Disc,
"landscape" => ImageType.Thumb,
"clearart" => ImageType.Art,
// unknown type (including "poster") --> primary
_ => ImageType.Primary,
};
}
}
}

Loading…
Cancel
Save