mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
Prefer MetadataProvider enum as provider id key over arbitrary strings
This commit is contained in:
parent
e87240b374
commit
7084541508
1 changed files with 21 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Entities
|
namespace MediaBrowser.Model.Entities
|
||||||
{
|
{
|
||||||
|
@ -9,6 +10,16 @@ namespace MediaBrowser.Model.Entities
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ProviderIdsExtensions
|
public static class ProviderIdsExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Case insensitive dictionary of <see cref="MetadataProvider"/> string representation.
|
||||||
|
/// </summary>
|
||||||
|
private static readonly Dictionary<string, string> _metadataProviderEnumDictionary =
|
||||||
|
Enum.GetValues<MetadataProvider>()
|
||||||
|
.ToDictionary(
|
||||||
|
enumValue => enumValue.ToString(),
|
||||||
|
enumValue => enumValue.ToString(),
|
||||||
|
StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if this instance has an id for the given provider.
|
/// Checks if this instance has an id for the given provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -108,7 +119,7 @@ namespace MediaBrowser.Model.Entities
|
||||||
/// <param name="instance">The instance.</param>
|
/// <param name="instance">The instance.</param>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
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)
|
if (instance == null)
|
||||||
{
|
{
|
||||||
|
@ -125,7 +136,15 @@ namespace MediaBrowser.Model.Entities
|
||||||
// Ensure it exists
|
// Ensure it exists
|
||||||
instance.ProviderIds ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
instance.ProviderIds ??= new Dictionary<string, string>(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue