瀏覽代碼

Use Uri.TryCreate and ImageType helper method

David 4 年之前
父節點
當前提交
6f898145af
共有 1 個文件被更改,包括 23 次插入18 次删除
  1. 23 18
      MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs

+ 23 - 18
MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs

@@ -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,
+            };
+        }
     }
 }