mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-31 21:08:27 +01:00
Add GPL modules
This commit is contained in:
103
MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
Normal file
103
MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Model.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ProviderIdsExtensions
|
||||
/// </summary>
|
||||
public static class ProviderIdsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether [has provider identifier] [the specified instance].
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <returns><c>true</c> if [has provider identifier] [the specified instance]; otherwise, <c>false</c>.</returns>
|
||||
public static bool HasProviderId(this IHasProviderIds instance, MetadataProviders provider)
|
||||
{
|
||||
return !string.IsNullOrEmpty(instance.GetProviderId(provider.ToString()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a provider id
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string GetProviderId(this IHasProviderIds instance, MetadataProviders provider)
|
||||
{
|
||||
return instance.GetProviderId(provider.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a provider id
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string GetProviderId(this IHasProviderIds instance, string name)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException("instance");
|
||||
}
|
||||
|
||||
if (instance.ProviderIds == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string id;
|
||||
instance.ProviderIds.TryGetValue(name, out id);
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
public static void SetProviderId(this IHasProviderIds instance, string name, string value)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
throw new ArgumentNullException("instance");
|
||||
}
|
||||
|
||||
// If it's null remove the key from the dictionary
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
if (instance.ProviderIds != null)
|
||||
{
|
||||
if (instance.ProviderIds.ContainsKey(name))
|
||||
{
|
||||
instance.ProviderIds.Remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure it exists
|
||||
if (instance.ProviderIds == null)
|
||||
{
|
||||
instance.ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
instance.ProviderIds[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
public static void SetProviderId(this IHasProviderIds instance, MetadataProviders provider, string value)
|
||||
{
|
||||
instance.SetProviderId(provider.ToString(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user