diff --git a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
index 11c3dbe42e..bde5a1da19 100644
--- a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
+++ b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs
@@ -9,6 +9,33 @@ namespace MediaBrowser.Model.Entities
///
public static class ProviderIdsExtensions
{
+ ///
+ /// Checks if this instance has an id for the given provider.
+ ///
+ /// The instance.
+ /// The of the provider name.
+ /// true if a provider id with the given name was found; otherwise false.
+ public static bool HasProviderId(this IHasProviderIds instance, string name)
+ {
+ if (instance == null)
+ {
+ throw new ArgumentNullException(nameof(instance));
+ }
+
+ return instance.ProviderIds?.ContainsKey(name) ?? false;
+ }
+
+ ///
+ /// Checks if this instance has an id for the given provider.
+ ///
+ /// The instance.
+ /// The provider.
+ /// true if a provider id with the given name was found; otherwise false.
+ public static bool HasProviderId(this IHasProviderIds instance, MetadataProvider provider)
+ {
+ return instance.HasProviderId(provider.ToString());
+ }
+
///
/// Gets a provider id.
///
diff --git a/tests/Jellyfin.Model.Tests/Entities/ProviderIdsExtensionsTests.cs b/tests/Jellyfin.Model.Tests/Entities/ProviderIdsExtensionsTests.cs
index c1a1525bad..2b2414ef1b 100644
--- a/tests/Jellyfin.Model.Tests/Entities/ProviderIdsExtensionsTests.cs
+++ b/tests/Jellyfin.Model.Tests/Entities/ProviderIdsExtensionsTests.cs
@@ -9,6 +9,44 @@ namespace Jellyfin.Model.Tests.Entities
{
private const string ExampleImdbId = "tt0113375";
+ [Fact]
+ public void HasProviderId_NullInstance_ThrowsArgumentNullException()
+ {
+ Assert.Throws(() => ProviderIdsExtensions.HasProviderId(null!, MetadataProvider.Imdb));
+ }
+
+ [Fact]
+ public void HasProviderId_NullProvider_False()
+ {
+ var nullProvider = new ProviderIdsExtensionsTestsObject()
+ {
+ ProviderIds = null!
+ };
+
+ Assert.False(nullProvider.HasProviderId(MetadataProvider.Imdb));
+ }
+
+ [Fact]
+ public void HasProviderId_NullName_ThrowsArgumentNullException()
+ {
+ Assert.Throws(() => ProviderIdsExtensionsTestsObject.Empty.HasProviderId(null!));
+ }
+
+ [Fact]
+ public void HasProviderId_NotFoundName_False()
+ {
+ Assert.False(ProviderIdsExtensionsTestsObject.Empty.HasProviderId(MetadataProvider.Imdb));
+ }
+
+ [Fact]
+ public void HasProviderId_FoundName_True()
+ {
+ var provider = new ProviderIdsExtensionsTestsObject();
+ provider.ProviderIds[MetadataProvider.Imdb.ToString()] = ExampleImdbId;
+
+ Assert.True(provider.HasProviderId(MetadataProvider.Imdb));
+ }
+
[Fact]
public void GetProviderId_NullInstance_ThrowsArgumentNullException()
{