mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-12-26 17:36:52 +00:00
Add TrySetProviderId extension
This commit is contained in:
parent
78ed8f660c
commit
ecd2dab0a2
|
@ -68,11 +68,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
|
|||
var justName = Path.GetFileName(item.Path.AsSpan());
|
||||
|
||||
var id = justName.GetAttributeValue("tmdbid");
|
||||
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tmdb, id);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Tmdb, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -373,22 +373,14 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
|
|||
{
|
||||
// Check for TMDb id
|
||||
var tmdbid = justName.GetAttributeValue("tmdbid");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tmdbid))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tmdb, tmdbid);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Tmdb, tmdbid);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(item.Path))
|
||||
{
|
||||
// Check for IMDb id - we use full media path, as we can assume that this will match in any use case (whether id in parent dir or in file name)
|
||||
var imdbid = item.Path.AsSpan().GetAttributeValue("imdbid");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(imdbid))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, imdbid);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, imdbid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,46 +186,25 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
|
|||
var justName = Path.GetFileName(path.AsSpan());
|
||||
|
||||
var imdbId = justName.GetAttributeValue("imdbid");
|
||||
if (!string.IsNullOrEmpty(imdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
|
||||
var tvdbId = justName.GetAttributeValue("tvdbid");
|
||||
if (!string.IsNullOrEmpty(tvdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tvdb, tvdbId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Tvdb, tvdbId);
|
||||
|
||||
var tvmazeId = justName.GetAttributeValue("tvmazeid");
|
||||
if (!string.IsNullOrEmpty(tvmazeId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.TvMaze, tvmazeId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.TvMaze, tvmazeId);
|
||||
|
||||
var tmdbId = justName.GetAttributeValue("tmdbid");
|
||||
if (!string.IsNullOrEmpty(tmdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tmdb, tmdbId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Tmdb, tmdbId);
|
||||
|
||||
var anidbId = justName.GetAttributeValue("anidbid");
|
||||
if (!string.IsNullOrEmpty(anidbId))
|
||||
{
|
||||
item.SetProviderId("AniDB", anidbId);
|
||||
}
|
||||
item.TrySetProviderId("AniDB", anidbId);
|
||||
|
||||
var aniListId = justName.GetAttributeValue("anilistid");
|
||||
if (!string.IsNullOrEmpty(aniListId))
|
||||
{
|
||||
item.SetProviderId("AniList", aniListId);
|
||||
}
|
||||
item.TrySetProviderId("AniList", aniListId);
|
||||
|
||||
var aniSearchId = justName.GetAttributeValue("anisearchid");
|
||||
if (!string.IsNullOrEmpty(aniSearchId))
|
||||
{
|
||||
item.SetProviderId("AniSearch", aniSearchId);
|
||||
}
|
||||
item.TrySetProviderId("AniSearch", aniSearchId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -365,10 +365,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||
break;
|
||||
case "CollectionNumber":
|
||||
var tmdbCollection = reader.ReadNormalizedString();
|
||||
if (!string.IsNullOrEmpty(tmdbCollection))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.TmdbCollection, tmdbCollection);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.TmdbCollection, tmdbCollection);
|
||||
|
||||
break;
|
||||
|
||||
|
@ -502,10 +499,7 @@ namespace MediaBrowser.LocalMetadata.Parsers
|
|||
if (_validProviderIds!.TryGetValue(readerName, out string? providerIdValue))
|
||||
{
|
||||
var id = reader.ReadElementContentAsString();
|
||||
if (!string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
item.SetProviderId(providerIdValue, id);
|
||||
}
|
||||
item.TrySetProviderId(providerIdValue, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1319,38 +1319,23 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||
// These support multiple values, but for now we only store the first.
|
||||
var mb = GetMultipleMusicBrainzId(tags.GetValueOrDefault("MusicBrainz Album Artist Id"))
|
||||
?? GetMultipleMusicBrainzId(tags.GetValueOrDefault("MUSICBRAINZ_ALBUMARTISTID"));
|
||||
if (!string.IsNullOrEmpty(mb))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, mb);
|
||||
}
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbumArtist, mb);
|
||||
|
||||
mb = GetMultipleMusicBrainzId(tags.GetValueOrDefault("MusicBrainz Artist Id"))
|
||||
?? GetMultipleMusicBrainzId(tags.GetValueOrDefault("MUSICBRAINZ_ARTISTID"));
|
||||
if (!string.IsNullOrEmpty(mb))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzArtist, mb);
|
||||
}
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzArtist, mb);
|
||||
|
||||
mb = GetMultipleMusicBrainzId(tags.GetValueOrDefault("MusicBrainz Album Id"))
|
||||
?? GetMultipleMusicBrainzId(tags.GetValueOrDefault("MUSICBRAINZ_ALBUMID"));
|
||||
if (!string.IsNullOrEmpty(mb))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, mb);
|
||||
}
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbum, mb);
|
||||
|
||||
mb = GetMultipleMusicBrainzId(tags.GetValueOrDefault("MusicBrainz Release Group Id"))
|
||||
?? GetMultipleMusicBrainzId(tags.GetValueOrDefault("MUSICBRAINZ_RELEASEGROUPID"));
|
||||
if (!string.IsNullOrEmpty(mb))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, mb);
|
||||
}
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzReleaseGroup, mb);
|
||||
|
||||
mb = GetMultipleMusicBrainzId(tags.GetValueOrDefault("MusicBrainz Release Track Id"))
|
||||
?? GetMultipleMusicBrainzId(tags.GetValueOrDefault("MUSICBRAINZ_RELEASETRACKID"));
|
||||
if (!string.IsNullOrEmpty(mb))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzTrack, mb);
|
||||
}
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzTrack, mb);
|
||||
}
|
||||
|
||||
private string GetMultipleMusicBrainzId(string value)
|
||||
|
|
|
@ -3,177 +3,214 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Model.Entities
|
||||
namespace MediaBrowser.Model.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Class ProviderIdsExtensions.
|
||||
/// </summary>
|
||||
public static class ProviderIdsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ProviderIdsExtensions.
|
||||
/// Case insensitive dictionary of <see cref="MetadataProvider"/> string representation.
|
||||
/// </summary>
|
||||
public static class ProviderIdsExtensions
|
||||
private static readonly Dictionary<string, string> _metadataProviderEnumDictionary =
|
||||
Enum.GetValues<MetadataProvider>()
|
||||
.ToDictionary(
|
||||
enumValue => enumValue.ToString(),
|
||||
enumValue => enumValue.ToString(),
|
||||
StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this instance has an id for the given provider.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The of the provider name.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool HasProviderId(this IHasProviderIds instance, string name)
|
||||
=> instance.TryGetProviderId(name, out _);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this instance has an id for the given provider.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool HasProviderId(this IHasProviderIds instance, MetadataProvider provider)
|
||||
=> instance.HasProviderId(provider.ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Gets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="id">The provider id.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool TryGetProviderId(this IHasProviderIds instance, string name, [NotNullWhen(true)] out string? id)
|
||||
{
|
||||
/// <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);
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this instance has an id for the given provider.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The of the provider name.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool HasProviderId(this IHasProviderIds instance, string name)
|
||||
if (instance.ProviderIds is null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
|
||||
return instance.TryGetProviderId(name, out _);
|
||||
id = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this instance has an id for the given provider.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool HasProviderId(this IHasProviderIds instance, MetadataProvider provider)
|
||||
var foundProviderId = instance.ProviderIds.TryGetValue(name, out id);
|
||||
// This occurs when searching with Identify (and possibly in other places)
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
return instance.HasProviderId(provider.ToString());
|
||||
id = null;
|
||||
foundProviderId = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="id">The provider id.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool TryGetProviderId(this IHasProviderIds instance, string name, [NotNullWhen(true)] out string? id)
|
||||
return foundProviderId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <param name="id">The provider id.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool TryGetProviderId(this IHasProviderIds instance, MetadataProvider provider, [NotNullWhen(true)] out string? id)
|
||||
{
|
||||
return instance.TryGetProviderId(provider.ToString(), out id);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
instance.TryGetProviderId(name, out string? id);
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <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, MetadataProvider provider)
|
||||
{
|
||||
return instance.GetProviderId(provider.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name, this should not contain a '=' character.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <remarks>Due to how deserialization from the database works the name can not contain '='.</remarks>
|
||||
/// <returns><c>true</c> if the provider id got set successfully; otherwise, <c>false</c>.</returns>
|
||||
public static bool TrySetProviderId(this IHasProviderIds instance, string? name, string? value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
|
||||
// When name contains a '=' it can't be deserialized from the database
|
||||
if (string.IsNullOrWhiteSpace(name)
|
||||
|| string.IsNullOrWhiteSpace(value)
|
||||
|| name.Contains('=', StringComparison.Ordinal))
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
|
||||
if (instance.ProviderIds is null)
|
||||
{
|
||||
id = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
var foundProviderId = instance.ProviderIds.TryGetValue(name, out id);
|
||||
// This occurs when searching with Identify (and possibly in other places)
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
id = null;
|
||||
foundProviderId = false;
|
||||
}
|
||||
|
||||
return foundProviderId;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <param name="id">The provider id.</param>
|
||||
/// <returns><c>true</c> if a provider id with the given name was found; otherwise <c>false</c>.</returns>
|
||||
public static bool TryGetProviderId(this IHasProviderIds instance, MetadataProvider provider, [NotNullWhen(true)] out string? id)
|
||||
// Ensure it exists
|
||||
instance.ProviderIds ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Match on internal MetadataProvider enum string values before adding arbitrary providers
|
||||
if (_metadataProviderEnumDictionary.TryGetValue(name, out var enumValue))
|
||||
{
|
||||
return instance.TryGetProviderId(provider.ToString(), out id);
|
||||
instance.ProviderIds[enumValue] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.ProviderIds[name] = value;
|
||||
}
|
||||
|
||||
/// <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)
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <returns><c>true</c> if the provider id got set successfully; otherwise, <c>false</c>.</returns>
|
||||
public static bool TrySetProviderId(this IHasProviderIds instance, MetadataProvider provider, string? value)
|
||||
=> instance.TrySetProviderId(provider.ToString(), value);
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name, this should not contain a '=' character.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <remarks>Due to how deserialization from the database works the name can not contain '='.</remarks>
|
||||
public static void SetProviderId(this IHasProviderIds instance, string name, string value)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(name);
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(value);
|
||||
|
||||
// When name contains a '=' it can't be deserialized from the database
|
||||
if (name.Contains('=', StringComparison.Ordinal))
|
||||
{
|
||||
instance.TryGetProviderId(name, out string? id);
|
||||
return id;
|
||||
throw new ArgumentException("Provider id name cannot contain '='", nameof(name));
|
||||
}
|
||||
|
||||
/// <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, MetadataProvider provider)
|
||||
// Ensure it exists
|
||||
instance.ProviderIds ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// Match on internal MetadataProvider enum string values before adding arbitrary providers
|
||||
if (_metadataProviderEnumDictionary.TryGetValue(name, out var enumValue))
|
||||
{
|
||||
return instance.GetProviderId(provider.ToString());
|
||||
instance.ProviderIds[enumValue] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name, this should not contain a '=' character.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <remarks>Due to how deserialization from the database works the name can not contain '='.</remarks>
|
||||
public static void SetProviderId(this IHasProviderIds instance, string name, string value)
|
||||
else
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
ArgumentException.ThrowIfNullOrEmpty(name);
|
||||
ArgumentException.ThrowIfNullOrEmpty(value);
|
||||
|
||||
// When name contains a '=' it can't be deserialized from the database
|
||||
if (name.Contains('=', StringComparison.Ordinal))
|
||||
{
|
||||
throw new ArgumentException("Provider id name cannot contain '='", nameof(name));
|
||||
}
|
||||
|
||||
// Ensure it exists
|
||||
instance.ProviderIds ??= new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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, MetadataProvider provider, string value)
|
||||
{
|
||||
instance.SetProviderId(provider.ToString(), value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
public static void RemoveProviderId(this IHasProviderIds instance, string name)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
ArgumentException.ThrowIfNullOrEmpty(name);
|
||||
|
||||
instance.ProviderIds?.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
public static void RemoveProviderId(this IHasProviderIds instance, MetadataProvider provider)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
|
||||
instance.ProviderIds?.Remove(provider.ToString());
|
||||
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, MetadataProvider provider, string value)
|
||||
=> instance.SetProviderId(provider.ToString(), value);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="name">The name.</param>
|
||||
public static void RemoveProviderId(this IHasProviderIds instance, string name)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
ArgumentException.ThrowIfNullOrEmpty(name);
|
||||
|
||||
instance.ProviderIds?.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a provider id.
|
||||
/// </summary>
|
||||
/// <param name="instance">The instance.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
public static void RemoveProviderId(this IHasProviderIds instance, MetadataProvider provider)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(instance);
|
||||
|
||||
instance.ProviderIds?.Remove(provider.ToString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -325,39 +325,32 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
audio.NormalizationGain = (float)tags.ReplayGainTrackGain;
|
||||
}
|
||||
|
||||
if ((options.ReplaceAllMetadata || !audio.TryGetProviderId(MetadataProvider.MusicBrainzArtist, out _))
|
||||
&& !string.IsNullOrEmpty(tags.MusicBrainzArtistId))
|
||||
if (options.ReplaceAllMetadata || !audio.HasProviderId(MetadataProvider.MusicBrainzArtist))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzArtist, tags.MusicBrainzArtistId);
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzArtist, tags.MusicBrainzArtistId);
|
||||
}
|
||||
|
||||
if ((options.ReplaceAllMetadata || !audio.TryGetProviderId(MetadataProvider.MusicBrainzAlbumArtist, out _))
|
||||
&& !string.IsNullOrEmpty(tags.MusicBrainzReleaseArtistId))
|
||||
if (options.ReplaceAllMetadata || !audio.HasProviderId(MetadataProvider.MusicBrainzAlbumArtist))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, tags.MusicBrainzReleaseArtistId);
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbumArtist, tags.MusicBrainzReleaseArtistId);
|
||||
}
|
||||
|
||||
if ((options.ReplaceAllMetadata || !audio.TryGetProviderId(MetadataProvider.MusicBrainzAlbum, out _))
|
||||
&& !string.IsNullOrEmpty(tags.MusicBrainzReleaseId))
|
||||
if (options.ReplaceAllMetadata || !audio.HasProviderId(MetadataProvider.MusicBrainzAlbum))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, tags.MusicBrainzReleaseId);
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzAlbum, tags.MusicBrainzReleaseId);
|
||||
}
|
||||
|
||||
if ((options.ReplaceAllMetadata || !audio.TryGetProviderId(MetadataProvider.MusicBrainzReleaseGroup, out _))
|
||||
&& !string.IsNullOrEmpty(tags.MusicBrainzReleaseGroupId))
|
||||
if (options.ReplaceAllMetadata || !audio.HasProviderId(MetadataProvider.MusicBrainzReleaseGroup))
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, tags.MusicBrainzReleaseGroupId);
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzReleaseGroup, tags.MusicBrainzReleaseGroupId);
|
||||
}
|
||||
|
||||
if (options.ReplaceAllMetadata || !audio.TryGetProviderId(MetadataProvider.MusicBrainzTrack, out _))
|
||||
if (options.ReplaceAllMetadata || !audio.HasProviderId(MetadataProvider.MusicBrainzTrack))
|
||||
{
|
||||
// Fallback to ffprobe as TagLib incorrectly provides recording MBID in `tags.MusicBrainzTrackId`.
|
||||
// See https://github.com/mono/taglib-sharp/issues/304
|
||||
var trackMbId = mediaInfo.GetProviderId(MetadataProvider.MusicBrainzTrack);
|
||||
if (trackMbId is not null)
|
||||
{
|
||||
audio.SetProviderId(MetadataProvider.MusicBrainzTrack, trackMbId);
|
||||
}
|
||||
audio.TrySetProviderId(MetadataProvider.MusicBrainzTrack, trackMbId);
|
||||
}
|
||||
|
||||
// Save extracted lyrics if they exist,
|
||||
|
|
|
@ -220,10 +220,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||
item.HomePageUrl = result.Website;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(result.imdbID))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, result.imdbID);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, result.imdbID);
|
||||
|
||||
ParseAdditionalMetadata(itemResult, result, isEnglishRequested);
|
||||
|
||||
|
|
|
@ -81,11 +81,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
|
|||
}
|
||||
|
||||
remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(movie.ImdbId))
|
||||
{
|
||||
remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
|
||||
}
|
||||
remoteResult.TrySetProviderId(MetadataProvider.Imdb, movie.ImdbId);
|
||||
|
||||
return new[] { remoteResult };
|
||||
}
|
||||
|
|
|
@ -56,10 +56,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
|||
}
|
||||
|
||||
result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture));
|
||||
if (!string.IsNullOrEmpty(personResult.ExternalIds.ImdbId))
|
||||
{
|
||||
result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId);
|
||||
}
|
||||
result.TrySetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId);
|
||||
|
||||
return new[] { result };
|
||||
}
|
||||
|
@ -129,11 +126,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
|
|||
}
|
||||
|
||||
item.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
if (!string.IsNullOrEmpty(person.ImdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, person.ImdbId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, person.ImdbId);
|
||||
|
||||
result.HasMetadata = true;
|
||||
result.Item = item;
|
||||
|
|
|
@ -187,20 +187,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
};
|
||||
|
||||
var externalIds = episodeResult.ExternalIds;
|
||||
if (!string.IsNullOrEmpty(externalIds?.TvdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tvdb, externalIds.TvdbId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(externalIds?.ImdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, externalIds.ImdbId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(externalIds?.TvrageId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.TvRage, externalIds.TvrageId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Tvdb, externalIds?.TvdbId);
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, externalIds?.ImdbId);
|
||||
item.TrySetProviderId(MetadataProvider.TvRage, externalIds?.TvrageId);
|
||||
|
||||
if (episodeResult.Videos?.Results is not null)
|
||||
{
|
||||
|
|
|
@ -73,10 +73,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
result.Item.Name = seasonResult.Name;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(seasonResult.ExternalIds?.TvdbId))
|
||||
{
|
||||
result.Item.SetProviderId(MetadataProvider.Tvdb, seasonResult.ExternalIds.TvdbId);
|
||||
}
|
||||
result.Item.TrySetProviderId(MetadataProvider.Tvdb, seasonResult.ExternalIds.TvdbId);
|
||||
|
||||
// TODO why was this disabled?
|
||||
var credits = seasonResult.Credits;
|
||||
|
|
|
@ -135,15 +135,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
remoteResult.SetProviderId(MetadataProvider.Tmdb, series.Id.ToString(CultureInfo.InvariantCulture));
|
||||
if (series.ExternalIds is not null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(series.ExternalIds.ImdbId))
|
||||
{
|
||||
remoteResult.SetProviderId(MetadataProvider.Imdb, series.ExternalIds.ImdbId);
|
||||
}
|
||||
remoteResult.TrySetProviderId(MetadataProvider.Imdb, series.ExternalIds.ImdbId);
|
||||
|
||||
if (!string.IsNullOrEmpty(series.ExternalIds.TvdbId))
|
||||
{
|
||||
remoteResult.SetProviderId(MetadataProvider.Tvdb, series.ExternalIds.TvdbId);
|
||||
}
|
||||
remoteResult.TrySetProviderId(MetadataProvider.Tvdb, series.ExternalIds.TvdbId);
|
||||
}
|
||||
|
||||
remoteResult.PremiereDate = series.FirstAirDate?.ToUniversalTime();
|
||||
|
@ -289,20 +283,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
|
|||
var ids = seriesResult.ExternalIds;
|
||||
if (ids is not null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(ids.ImdbId))
|
||||
{
|
||||
series.SetProviderId(MetadataProvider.Imdb, ids.ImdbId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(ids.TvrageId))
|
||||
{
|
||||
series.SetProviderId(MetadataProvider.TvRage, ids.TvrageId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(ids.TvdbId))
|
||||
{
|
||||
series.SetProviderId(MetadataProvider.Tvdb, ids.TvdbId);
|
||||
}
|
||||
series.TrySetProviderId(MetadataProvider.Imdb, ids.ImdbId);
|
||||
series.TrySetProviderId(MetadataProvider.TvRage, ids.TvrageId);
|
||||
series.TrySetProviderId(MetadataProvider.Tvdb, ids.TvdbId);
|
||||
}
|
||||
|
||||
var contentRatings = seriesResult.ContentRatings.Results ?? new List<ContentRating>();
|
||||
|
|
|
@ -572,10 +572,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
|
||||
var provider = reader.GetAttribute("type");
|
||||
var providerId = reader.ReadElementContentAsString();
|
||||
if (!string.IsNullOrWhiteSpace(provider) && !string.IsNullOrWhiteSpace(providerId))
|
||||
{
|
||||
item.SetProviderId(provider, providerId);
|
||||
}
|
||||
item.TrySetProviderId(provider, providerId);
|
||||
|
||||
break;
|
||||
case "thumb":
|
||||
|
@ -604,10 +601,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
if (_validProviderIds.TryGetValue(readerName, out string? providerIdValue))
|
||||
{
|
||||
var id = reader.ReadElementContentAsString();
|
||||
if (!string.IsNullOrWhiteSpace(providerIdValue) && !string.IsNullOrWhiteSpace(id))
|
||||
{
|
||||
item.SetProviderId(providerIdValue, id);
|
||||
}
|
||||
item.TrySetProviderId(providerIdValue, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -65,15 +65,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
tmdbId = contentId;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(imdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tmdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tmdb, tmdbId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
item.TrySetProviderId(MetadataProvider.Tmdb, tmdbId);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -83,10 +76,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
var movie = item as Movie;
|
||||
|
||||
var tmdbcolid = reader.GetAttribute("tmdbcolid");
|
||||
if (!string.IsNullOrWhiteSpace(tmdbcolid) && movie is not null)
|
||||
{
|
||||
movie.SetProviderId(MetadataProvider.TmdbCollection, tmdbcolid);
|
||||
}
|
||||
movie?.TrySetProviderId(MetadataProvider.TmdbCollection, tmdbcolid);
|
||||
|
||||
var val = reader.ReadInnerXml();
|
||||
|
||||
|
|
|
@ -48,29 +48,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers
|
|||
{
|
||||
case "id":
|
||||
{
|
||||
string? imdbId = reader.GetAttribute("IMDB");
|
||||
string? tmdbId = reader.GetAttribute("TMDB");
|
||||
string? tvdbId = reader.GetAttribute("TVDB");
|
||||
item.TrySetProviderId(MetadataProvider.Imdb, reader.GetAttribute("IMDB"));
|
||||
item.TrySetProviderId(MetadataProvider.Tmdb, reader.GetAttribute("TMDB"));
|
||||
|
||||
string? tvdbId = reader.GetAttribute("TVDB");
|
||||
if (string.IsNullOrWhiteSpace(tvdbId))
|
||||
{
|
||||
tvdbId = reader.ReadElementContentAsString();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(imdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Imdb, imdbId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tmdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tmdb, tmdbId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tvdbId))
|
||||
{
|
||||
item.SetProviderId(MetadataProvider.Tvdb, tvdbId);
|
||||
}
|
||||
item.TrySetProviderId(MetadataProvider.Tvdb, tvdbId);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -479,10 +479,7 @@ public class GuideManager : IGuideManager
|
|||
DateModified = DateTime.UtcNow
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(info.Etag))
|
||||
{
|
||||
item.SetProviderId(EtagKey, info.Etag);
|
||||
}
|
||||
item.TrySetProviderId(EtagKey, info.Etag);
|
||||
}
|
||||
|
||||
if (!string.Equals(info.ShowId, item.ShowId, StringComparison.OrdinalIgnoreCase))
|
||||
|
|
Loading…
Reference in a new issue