From 13df026f6b8d288acc0201d1076ed0c401c61043 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Wed, 27 Apr 2022 18:16:31 -0600 Subject: [PATCH] Merge pull request #7654 from Shadowghost/nfo-provider-fix Prefer MetadataProvider enum as provider id key over arbitrary strings (cherry picked from commit a2abae3014578e8d9c7f1b54140fe3dcf1503ad2) Signed-off-by: crobibero --- .../Entities/ProviderIdsExtensions.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs index ce4b0ec92e..62a2f3ce84 100644 --- a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs +++ b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; namespace MediaBrowser.Model.Entities { @@ -9,6 +10,16 @@ namespace MediaBrowser.Model.Entities /// public static class ProviderIdsExtensions { + /// + /// Case insensitive dictionary of string representation. + /// + private static readonly Dictionary _metadataProviderEnumDictionary = + Enum.GetValues() + .ToDictionary( + enumValue => enumValue.ToString(), + enumValue => enumValue.ToString(), + StringComparer.OrdinalIgnoreCase); + /// /// Checks if this instance has an id for the given provider. /// @@ -108,7 +119,7 @@ namespace MediaBrowser.Model.Entities /// The instance. /// The name. /// The value. - public static void SetProviderId(this IHasProviderIds instance, string name, string value) + public static void SetProviderId(this IHasProviderIds instance, string name, string? value) { if (instance == null) { @@ -125,7 +136,15 @@ namespace MediaBrowser.Model.Entities // Ensure it exists instance.ProviderIds ??= new Dictionary(StringComparer.OrdinalIgnoreCase); - instance.ProviderIds[name] = value; + // Match on internal MetadataProvider enum string values before adding arbitrary providers + if (_metadataProviderEnumDictionary.TryGetValue(name, out var enumValue)) + { + instance.ProviderIds[enumValue] = value; + } + else + { + instance.ProviderIds[name] = value; + } } }