From ecd2dab0a2550c80ae054576d9c05ddb24d5e47b Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Wed, 17 Jul 2024 15:48:21 +0200 Subject: [PATCH] Add TrySetProviderId extension --- .../Resolvers/Movies/BoxSetResolver.cs | 6 +- .../Library/Resolvers/Movies/MovieResolver.cs | 12 +- .../Library/Resolvers/TV/SeriesResolver.cs | 35 +- .../Parsers/BaseItemXmlParser.cs | 10 +- .../Probing/ProbeResultNormalizer.cs | 25 +- .../Entities/ProviderIdsExtensions.cs | 333 ++++++++++-------- .../MediaInfo/AudioFileProber.cs | 27 +- .../Plugins/Omdb/OmdbProvider.cs | 5 +- .../Plugins/Tmdb/Movies/TmdbMovieProvider.cs | 6 +- .../Plugins/Tmdb/People/TmdbPersonProvider.cs | 11 +- .../Plugins/Tmdb/TV/TmdbEpisodeProvider.cs | 17 +- .../Plugins/Tmdb/TV/TmdbSeasonProvider.cs | 5 +- .../Plugins/Tmdb/TV/TmdbSeriesProvider.cs | 27 +- .../Parsers/BaseNfoParser.cs | 10 +- .../Parsers/MovieNfoParser.cs | 16 +- .../Parsers/SeriesNfoParser.cs | 21 +- src/Jellyfin.LiveTv/Guide/GuideManager.cs | 5 +- 17 files changed, 235 insertions(+), 336 deletions(-) diff --git a/Emby.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs index 955055313e..4b15073858 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Movies/BoxSetResolver.cs @@ -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); } } } diff --git a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 1a210e3cc8..4debe722b9 100644 --- a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -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); } } } diff --git a/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs index 1484c34bcc..fb48d7bf17 100644 --- a/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs @@ -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); } } } diff --git a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs index a7e027d94a..e4ac59b676 100644 --- a/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs +++ b/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs @@ -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 { diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index f5185398cd..3aafb733da 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -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) diff --git a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs index 1c73091f0d..479ec7712d 100644 --- a/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs +++ b/MediaBrowser.Model/Entities/ProviderIdsExtensions.cs @@ -3,177 +3,214 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -namespace MediaBrowser.Model.Entities +namespace MediaBrowser.Model.Entities; + +/// +/// Class ProviderIdsExtensions. +/// +public static class ProviderIdsExtensions { /// - /// Class ProviderIdsExtensions. + /// Case insensitive dictionary of string representation. /// - public static class ProviderIdsExtensions + 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. + /// + /// 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) + => instance.TryGetProviderId(name, out _); + + /// + /// 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) + => instance.HasProviderId(provider.ToString()); + + /// + /// Gets a provider id. + /// + /// The instance. + /// The name. + /// The provider id. + /// true if a provider id with the given name was found; otherwise false. + public static bool TryGetProviderId(this IHasProviderIds instance, string name, [NotNullWhen(true)] out string? id) { - /// - /// Case insensitive dictionary of string representation. - /// - private static readonly Dictionary _metadataProviderEnumDictionary = - Enum.GetValues() - .ToDictionary( - enumValue => enumValue.ToString(), - enumValue => enumValue.ToString(), - StringComparer.OrdinalIgnoreCase); + ArgumentNullException.ThrowIfNull(instance); - /// - /// 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.ProviderIds is null) { - ArgumentNullException.ThrowIfNull(instance); - - return instance.TryGetProviderId(name, out _); + id = null; + return 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) + 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; } - /// - /// Gets a provider id. - /// - /// The instance. - /// The name. - /// The provider id. - /// true if a provider id with the given name was found; otherwise false. - public static bool TryGetProviderId(this IHasProviderIds instance, string name, [NotNullWhen(true)] out string? id) + return foundProviderId; + } + + /// + /// Gets a provider id. + /// + /// The instance. + /// The provider. + /// The provider id. + /// true if a provider id with the given name was found; otherwise false. + public static bool TryGetProviderId(this IHasProviderIds instance, MetadataProvider provider, [NotNullWhen(true)] out string? id) + { + return instance.TryGetProviderId(provider.ToString(), out id); + } + + /// + /// Gets a provider id. + /// + /// The instance. + /// The name. + /// System.String. + public static string? GetProviderId(this IHasProviderIds instance, string name) + { + instance.TryGetProviderId(name, out string? id); + return id; + } + + /// + /// Gets a provider id. + /// + /// The instance. + /// The provider. + /// System.String. + public static string? GetProviderId(this IHasProviderIds instance, MetadataProvider provider) + { + return instance.GetProviderId(provider.ToString()); + } + + /// + /// Sets a provider id. + /// + /// The instance. + /// The name, this should not contain a '=' character. + /// The value. + /// Due to how deserialization from the database works the name can not contain '='. + /// true if the provider id got set successfully; otherwise, false. + 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; } - /// - /// Gets a provider id. - /// - /// The instance. - /// The provider. - /// The provider id. - /// true if a provider id with the given name was found; otherwise false. - public static bool TryGetProviderId(this IHasProviderIds instance, MetadataProvider provider, [NotNullWhen(true)] out string? id) + // Ensure it exists + instance.ProviderIds ??= new Dictionary(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; } - /// - /// Gets a provider id. - /// - /// The instance. - /// The name. - /// System.String. - public static string? GetProviderId(this IHasProviderIds instance, string name) + return true; + } + + /// + /// Sets a provider id. + /// + /// The instance. + /// The provider. + /// The value. + /// true if the provider id got set successfully; otherwise, false. + public static bool TrySetProviderId(this IHasProviderIds instance, MetadataProvider provider, string? value) + => instance.TrySetProviderId(provider.ToString(), value); + + /// + /// Sets a provider id. + /// + /// The instance. + /// The name, this should not contain a '=' character. + /// The value. + /// Due to how deserialization from the database works the name can not contain '='. + 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)); } - /// - /// Gets a provider id. - /// - /// The instance. - /// The provider. - /// System.String. - public static string? GetProviderId(this IHasProviderIds instance, MetadataProvider provider) + // Ensure it exists + instance.ProviderIds ??= new Dictionary(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; } - - /// - /// Sets a provider id. - /// - /// The instance. - /// The name, this should not contain a '=' character. - /// The value. - /// Due to how deserialization from the database works the name can not contain '='. - 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(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; - } - } - - /// - /// Sets a provider id. - /// - /// The instance. - /// The provider. - /// The value. - public static void SetProviderId(this IHasProviderIds instance, MetadataProvider provider, string value) - { - instance.SetProviderId(provider.ToString(), value); - } - - /// - /// Removes a provider id. - /// - /// The instance. - /// The name. - public static void RemoveProviderId(this IHasProviderIds instance, string name) - { - ArgumentNullException.ThrowIfNull(instance); - ArgumentException.ThrowIfNullOrEmpty(name); - - instance.ProviderIds?.Remove(name); - } - - /// - /// Removes a provider id. - /// - /// The instance. - /// The provider. - public static void RemoveProviderId(this IHasProviderIds instance, MetadataProvider provider) - { - ArgumentNullException.ThrowIfNull(instance); - - instance.ProviderIds?.Remove(provider.ToString()); + instance.ProviderIds[name] = value; } } + + /// + /// Sets a provider id. + /// + /// The instance. + /// The provider. + /// The value. + public static void SetProviderId(this IHasProviderIds instance, MetadataProvider provider, string value) + => instance.SetProviderId(provider.ToString(), value); + + /// + /// Removes a provider id. + /// + /// The instance. + /// The name. + public static void RemoveProviderId(this IHasProviderIds instance, string name) + { + ArgumentNullException.ThrowIfNull(instance); + ArgumentException.ThrowIfNullOrEmpty(name); + + instance.ProviderIds?.Remove(name); + } + + /// + /// Removes a provider id. + /// + /// The instance. + /// The provider. + public static void RemoveProviderId(this IHasProviderIds instance, MetadataProvider provider) + { + ArgumentNullException.ThrowIfNull(instance); + + instance.ProviderIds?.Remove(provider.ToString()); + } } diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs index 0083d4f75f..fbafd55187 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs @@ -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, diff --git a/MediaBrowser.Providers/Plugins/Omdb/OmdbProvider.cs b/MediaBrowser.Providers/Plugins/Omdb/OmdbProvider.cs index c750caa1c9..de0da7f7bd 100644 --- a/MediaBrowser.Providers/Plugins/Omdb/OmdbProvider.cs +++ b/MediaBrowser.Providers/Plugins/Omdb/OmdbProvider.cs @@ -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); diff --git a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs index dac7a74ed8..8d68e2dcfe 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/Movies/TmdbMovieProvider.cs @@ -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 }; } diff --git a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonProvider.cs index 5c6e71fd89..98c46895d7 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/People/TmdbPersonProvider.cs @@ -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; diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs index 489f5e2a17..e628abde55 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbEpisodeProvider.cs @@ -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) { diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs index 10efb68b94..3f208b5993 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeasonProvider.cs @@ -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; diff --git a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs index d8476bd47d..e4062740fe 100644 --- a/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs +++ b/MediaBrowser.Providers/Plugins/Tmdb/TV/TmdbSeriesProvider.cs @@ -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(); diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index d049c5a8ef..f2681500b0 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -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 { diff --git a/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs index af867cd59f..2d65188b63 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs @@ -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(); diff --git a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs index d99e11bcd9..59abef919e 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs @@ -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; } diff --git a/src/Jellyfin.LiveTv/Guide/GuideManager.cs b/src/Jellyfin.LiveTv/Guide/GuideManager.cs index 093970c38b..f657422a04 100644 --- a/src/Jellyfin.LiveTv/Guide/GuideManager.cs +++ b/src/Jellyfin.LiveTv/Guide/GuideManager.cs @@ -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))