Enable nullable for more files

This commit is contained in:
Bond_009 2023-02-25 17:20:53 +01:00
parent 3b0a182045
commit e35119987a
7 changed files with 69 additions and 59 deletions

View File

@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;

View File

@ -1,5 +1,3 @@
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;

View File

@ -62,32 +62,35 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
cancellationToken) cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
var remoteResult = new RemoteSearchResult if (movie is not null)
{ {
Name = movie.Title ?? movie.OriginalTitle, var remoteResult = new RemoteSearchResult
SearchProviderName = Name, {
ImageUrl = _tmdbClientManager.GetPosterUrl(movie.PosterPath), Name = movie.Title ?? movie.OriginalTitle,
Overview = movie.Overview SearchProviderName = Name,
}; ImageUrl = _tmdbClientManager.GetPosterUrl(movie.PosterPath),
Overview = movie.Overview
};
if (movie.ReleaseDate is not null) if (movie.ReleaseDate is not null)
{ {
var releaseDate = movie.ReleaseDate.Value.ToUniversalTime(); var releaseDate = movie.ReleaseDate.Value.ToUniversalTime();
remoteResult.PremiereDate = releaseDate; remoteResult.PremiereDate = releaseDate;
remoteResult.ProductionYear = releaseDate.Year; remoteResult.ProductionYear = releaseDate.Year;
}
remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));
if (!string.IsNullOrWhiteSpace(movie.ImdbId))
{
remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
}
return new[] { remoteResult };
} }
remoteResult.SetProviderId(MetadataProvider.Tmdb, movie.Id.ToString(CultureInfo.InvariantCulture));
if (!string.IsNullOrWhiteSpace(movie.ImdbId))
{
remoteResult.SetProviderId(MetadataProvider.Imdb, movie.ImdbId);
}
return new[] { remoteResult };
} }
IReadOnlyList<SearchMovie> movieResults; IReadOnlyList<SearchMovie>? movieResults = null;
if (searchInfo.TryGetProviderId(MetadataProvider.Imdb, out id)) if (searchInfo.TryGetProviderId(MetadataProvider.Imdb, out id))
{ {
var result = await _tmdbClientManager.FindByExternalIdAsync( var result = await _tmdbClientManager.FindByExternalIdAsync(
@ -95,18 +98,20 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
FindExternalSource.Imdb, FindExternalSource.Imdb,
TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage), TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
movieResults = result.MovieResults; movieResults = result?.MovieResults;
} }
else if (searchInfo.TryGetProviderId(MetadataProvider.Tvdb, out id))
if (movieResults is null && searchInfo.TryGetProviderId(MetadataProvider.Tvdb, out id))
{ {
var result = await _tmdbClientManager.FindByExternalIdAsync( var result = await _tmdbClientManager.FindByExternalIdAsync(
id, id,
FindExternalSource.TvDb, FindExternalSource.TvDb,
TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage), TmdbUtils.GetImageLanguagesParam(searchInfo.MetadataLanguage),
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
movieResults = result.MovieResults; movieResults = result?.MovieResults;
} }
else
if (movieResults is null)
{ {
movieResults = await _tmdbClientManager movieResults = await _tmdbClientManager
.SearchMovieAsync(searchInfo.Name, searchInfo.Year ?? 0, searchInfo.MetadataLanguage, cancellationToken) .SearchMovieAsync(searchInfo.Name, searchInfo.Year ?? 0, searchInfo.MetadataLanguage, cancellationToken)

View File

@ -105,6 +105,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
if (personTmdbId > 0) if (personTmdbId > 0)
{ {
var person = await _tmdbClientManager.GetPersonAsync(personTmdbId, info.MetadataLanguage, cancellationToken).ConfigureAwait(false); var person = await _tmdbClientManager.GetPersonAsync(personTmdbId, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
if (person is null)
{
return result;
}
result.HasMetadata = true; result.HasMetadata = true;

View File

@ -209,7 +209,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
} }
} }
if (string.IsNullOrEmpty(tmdbId)) if (!int.TryParse(tmdbId, CultureInfo.InvariantCulture, out int tmdbIdInt))
{ {
return result; return result;
} }
@ -217,9 +217,14 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var tvShow = await _tmdbClientManager var tvShow = await _tmdbClientManager
.GetSeriesAsync(Convert.ToInt32(tmdbId, CultureInfo.InvariantCulture), info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken) .GetSeriesAsync(tmdbIdInt, info.MetadataLanguage, TmdbUtils.GetImageLanguagesParam(info.MetadataLanguage), cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
if (tvShow is null)
{
return result;
}
result = new MetadataResult<Series> result = new MetadataResult<Series>
{ {
Item = MapTvShowToSeries(tvShow, info.MetadataCountryCode), Item = MapTvShowToSeries(tvShow, info.MetadataCountryCode),

View File

@ -1,6 +1,4 @@
#nullable disable using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
@ -50,10 +48,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="imageLanguages">A comma-separated list of image languages.</param> /// <param name="imageLanguages">A comma-separated list of image languages.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb movie or null if not found.</returns> /// <returns>The TMDb movie or null if not found.</returns>
public async Task<Movie> GetMovieAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken) public async Task<Movie?> GetMovieAsync(int tmdbId, string? language, string? imageLanguages, CancellationToken cancellationToken)
{ {
var key = $"movie-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"movie-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out Movie movie)) if (_memoryCache.TryGetValue(key, out Movie? movie))
{ {
return movie; return movie;
} }
@ -89,10 +87,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="imageLanguages">A comma-separated list of image languages.</param> /// <param name="imageLanguages">A comma-separated list of image languages.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb collection or null if not found.</returns> /// <returns>The TMDb collection or null if not found.</returns>
public async Task<Collection> GetCollectionAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken) public async Task<Collection?> GetCollectionAsync(int tmdbId, string? language, string? imageLanguages, CancellationToken cancellationToken)
{ {
var key = $"collection-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"collection-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out Collection collection)) if (_memoryCache.TryGetValue(key, out Collection? collection))
{ {
return collection; return collection;
} }
@ -122,10 +120,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="imageLanguages">A comma-separated list of image languages.</param> /// <param name="imageLanguages">A comma-separated list of image languages.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb tv show information or null if not found.</returns> /// <returns>The TMDb tv show information or null if not found.</returns>
public async Task<TvShow> GetSeriesAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken) public async Task<TvShow?> GetSeriesAsync(int tmdbId, string? language, string? imageLanguages, CancellationToken cancellationToken)
{ {
var key = $"series-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"series-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out TvShow series)) if (_memoryCache.TryGetValue(key, out TvShow? series))
{ {
return series; return series;
} }
@ -162,7 +160,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="imageLanguages">A comma-separated list of image languages.</param> /// <param name="imageLanguages">A comma-separated list of image languages.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb tv show episode group information or null if not found.</returns> /// <returns>The TMDb tv show episode group information or null if not found.</returns>
private async Task<TvGroupCollection> GetSeriesGroupAsync(int tvShowId, string displayOrder, string language, string imageLanguages, CancellationToken cancellationToken) private async Task<TvGroupCollection?> GetSeriesGroupAsync(int tvShowId, string displayOrder, string? language, string? imageLanguages, CancellationToken cancellationToken)
{ {
TvGroupType? groupType = TvGroupType? groupType =
string.Equals(displayOrder, "originalAirDate", StringComparison.Ordinal) ? TvGroupType.OriginalAirDate : string.Equals(displayOrder, "originalAirDate", StringComparison.Ordinal) ? TvGroupType.OriginalAirDate :
@ -180,7 +178,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
} }
var key = $"group-{tvShowId.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}"; var key = $"group-{tvShowId.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}";
if (_memoryCache.TryGetValue(key, out TvGroupCollection group)) if (_memoryCache.TryGetValue(key, out TvGroupCollection? group))
{ {
return group; return group;
} }
@ -217,10 +215,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="imageLanguages">A comma-separated list of image languages.</param> /// <param name="imageLanguages">A comma-separated list of image languages.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb tv season information or null if not found.</returns> /// <returns>The TMDb tv season information or null if not found.</returns>
public async Task<TvSeason> GetSeasonAsync(int tvShowId, int seasonNumber, string language, string imageLanguages, CancellationToken cancellationToken) public async Task<TvSeason?> GetSeasonAsync(int tvShowId, int seasonNumber, string? language, string? imageLanguages, CancellationToken cancellationToken)
{ {
var key = $"season-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"season-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out TvSeason season)) if (_memoryCache.TryGetValue(key, out TvSeason? season))
{ {
return season; return season;
} }
@ -254,10 +252,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="imageLanguages">A comma-separated list of image languages.</param> /// <param name="imageLanguages">A comma-separated list of image languages.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb tv episode information or null if not found.</returns> /// <returns>The TMDb tv episode information or null if not found.</returns>
public async Task<TvEpisode> GetEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, string displayOrder, string language, string imageLanguages, CancellationToken cancellationToken) public async Task<TvEpisode?> GetEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, string displayOrder, string? language, string? imageLanguages, CancellationToken cancellationToken)
{ {
var key = $"episode-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}e{episodeNumber.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}"; var key = $"episode-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}e{episodeNumber.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}";
if (_memoryCache.TryGetValue(key, out TvEpisode episode)) if (_memoryCache.TryGetValue(key, out TvEpisode? episode))
{ {
return episode; return episode;
} }
@ -301,10 +299,10 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="language">The episode's language.</param> /// <param name="language">The episode's language.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb person information or null if not found.</returns> /// <returns>The TMDb person information or null if not found.</returns>
public async Task<Person> GetPersonAsync(int personTmdbId, string language, CancellationToken cancellationToken) public async Task<Person?> GetPersonAsync(int personTmdbId, string language, CancellationToken cancellationToken)
{ {
var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out Person person)) if (_memoryCache.TryGetValue(key, out Person? person))
{ {
return person; return person;
} }
@ -333,14 +331,14 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="language">The item's language.</param> /// <param name="language">The item's language.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The TMDb item or null if not found.</returns> /// <returns>The TMDb item or null if not found.</returns>
public async Task<FindContainer> FindByExternalIdAsync( public async Task<FindContainer?> FindByExternalIdAsync(
string externalId, string externalId,
FindExternalSource source, FindExternalSource source,
string language, string language,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var key = $"find-{source.ToString()}-{externalId.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"find-{source.ToString()}-{externalId.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out FindContainer result)) if (_memoryCache.TryGetValue(key, out FindContainer? result))
{ {
return result; return result;
} }
@ -372,7 +370,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
public async Task<IReadOnlyList<SearchTv>> SearchSeriesAsync(string name, string language, int year = 0, CancellationToken cancellationToken = default) public async Task<IReadOnlyList<SearchTv>> SearchSeriesAsync(string name, string language, int year = 0, CancellationToken cancellationToken = default)
{ {
var key = $"searchseries-{name}-{language}"; var key = $"searchseries-{name}-{language}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchTv> series)) if (_memoryCache.TryGetValue(key, out SearchContainer<SearchTv>? series) && series is not null)
{ {
return series.Results; return series.Results;
} }
@ -400,7 +398,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
public async Task<IReadOnlyList<SearchPerson>> SearchPersonAsync(string name, CancellationToken cancellationToken) public async Task<IReadOnlyList<SearchPerson>> SearchPersonAsync(string name, CancellationToken cancellationToken)
{ {
var key = $"searchperson-{name}"; var key = $"searchperson-{name}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchPerson> person)) if (_memoryCache.TryGetValue(key, out SearchContainer<SearchPerson>? person) && person is not null)
{ {
return person.Results; return person.Results;
} }
@ -442,7 +440,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
public async Task<IReadOnlyList<SearchMovie>> SearchMovieAsync(string name, int year, string language, CancellationToken cancellationToken) public async Task<IReadOnlyList<SearchMovie>> SearchMovieAsync(string name, int year, string language, CancellationToken cancellationToken)
{ {
var key = $"moviesearch-{name}-{year.ToString(CultureInfo.InvariantCulture)}-{language}"; var key = $"moviesearch-{name}-{year.ToString(CultureInfo.InvariantCulture)}-{language}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchMovie> movies)) if (_memoryCache.TryGetValue(key, out SearchContainer<SearchMovie>? movies) && movies is not null)
{ {
return movies.Results; return movies.Results;
} }
@ -471,7 +469,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
public async Task<IReadOnlyList<SearchCollection>> SearchCollectionAsync(string name, string language, CancellationToken cancellationToken) public async Task<IReadOnlyList<SearchCollection>> SearchCollectionAsync(string name, string language, CancellationToken cancellationToken)
{ {
var key = $"collectionsearch-{name}-{language}"; var key = $"collectionsearch-{name}-{language}";
if (_memoryCache.TryGetValue(key, out SearchContainer<SearchCollection> collections)) if (_memoryCache.TryGetValue(key, out SearchContainer<SearchCollection>? collections) && collections is not null)
{ {
return collections.Results; return collections.Results;
} }
@ -496,7 +494,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="size">The image size to fetch.</param> /// <param name="size">The image size to fetch.</param>
/// <param name="path">The relative URL of the image.</param> /// <param name="path">The relative URL of the image.</param>
/// <returns>The absolute URL.</returns> /// <returns>The absolute URL.</returns>
private string GetUrl(string size, string path) private string? GetUrl(string? size, string path)
{ {
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
@ -511,7 +509,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// </summary> /// </summary>
/// <param name="posterPath">The relative URL of the poster.</param> /// <param name="posterPath">The relative URL of the poster.</param>
/// <returns>The absolute URL.</returns> /// <returns>The absolute URL.</returns>
public string GetPosterUrl(string posterPath) public string? GetPosterUrl(string posterPath)
{ {
return GetUrl(Plugin.Instance.Configuration.PosterSize, posterPath); return GetUrl(Plugin.Instance.Configuration.PosterSize, posterPath);
} }
@ -521,7 +519,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// </summary> /// </summary>
/// <param name="actorProfilePath">The relative URL of the profile image.</param> /// <param name="actorProfilePath">The relative URL of the profile image.</param>
/// <returns>The absolute URL.</returns> /// <returns>The absolute URL.</returns>
public string GetProfileUrl(string actorProfilePath) public string? GetProfileUrl(string actorProfilePath)
{ {
return GetUrl(Plugin.Instance.Configuration.ProfileSize, actorProfilePath); return GetUrl(Plugin.Instance.Configuration.ProfileSize, actorProfilePath);
} }
@ -579,7 +577,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="type">The type of the image.</param> /// <param name="type">The type of the image.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <returns>The remote images.</returns> /// <returns>The remote images.</returns>
private IEnumerable<RemoteImageInfo> ConvertToRemoteImageInfo(IReadOnlyList<ImageData> images, string size, ImageType type, string requestLanguage) private IEnumerable<RemoteImageInfo> ConvertToRemoteImageInfo(IReadOnlyList<ImageData> images, string? size, ImageType type, string requestLanguage)
{ {
// sizes provided are for original resolution, don't store them when downloading scaled images // sizes provided are for original resolution, don't store them when downloading scaled images
var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase); var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase);

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using TMDbLib.Objects.General; using TMDbLib.Objects.General;
@ -128,7 +129,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// </summary> /// </summary>
/// <param name="language">The language code.</param> /// <param name="language">The language code.</param>
/// <returns>The normalized language code.</returns> /// <returns>The normalized language code.</returns>
public static string NormalizeLanguage(string language) [return: NotNullIfNotNull(nameof(language))]
public static string? NormalizeLanguage(string? language)
{ {
if (string.IsNullOrEmpty(language)) if (string.IsNullOrEmpty(language))
{ {