| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Globalization; |
| | | 4 | | using System.Threading; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using MediaBrowser.Model.Dto; |
| | | 7 | | using MediaBrowser.Model.Entities; |
| | | 8 | | using MediaBrowser.Model.Providers; |
| | | 9 | | using Microsoft.Extensions.Caching.Memory; |
| | | 10 | | using TMDbLib.Client; |
| | | 11 | | using TMDbLib.Objects.Collections; |
| | | 12 | | using TMDbLib.Objects.Find; |
| | | 13 | | using TMDbLib.Objects.General; |
| | | 14 | | using TMDbLib.Objects.Movies; |
| | | 15 | | using TMDbLib.Objects.People; |
| | | 16 | | using TMDbLib.Objects.Search; |
| | | 17 | | using TMDbLib.Objects.TvShows; |
| | | 18 | | |
| | | 19 | | namespace MediaBrowser.Providers.Plugins.Tmdb |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Manager class for abstracting the TMDb API client library. |
| | | 23 | | /// </summary> |
| | | 24 | | public class TmdbClientManager : IDisposable |
| | | 25 | | { |
| | | 26 | | private const int CacheDurationInHours = 1; |
| | | 27 | | |
| | | 28 | | // Sized in TMDb records - see EstimateSize - rather than in responses, because the responses |
| | | 29 | | // differ in weight by orders of magnitude. |
| | | 30 | | private const int CacheSizeLimit = 100_000; |
| | | 31 | | |
| | 0 | 32 | | private static readonly Dictionary<string, string> ThumbnailSizes = new Dictionary<string, string> |
| | 0 | 33 | | { |
| | 0 | 34 | | { "Primary", "w500" }, |
| | 0 | 35 | | { "Backdrop", "w780" }, |
| | 0 | 36 | | { "Thumb", "w780" }, |
| | 0 | 37 | | { "Logo", "w500" }, |
| | 0 | 38 | | }; |
| | | 39 | | |
| | | 40 | | private readonly MemoryCache _memoryCache; |
| | | 41 | | private readonly TMDbClient _tmDbClient; |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Initializes a new instance of the <see cref="TmdbClientManager"/> class. |
| | | 45 | | /// </summary> |
| | | 46 | | public TmdbClientManager() |
| | | 47 | | { |
| | 27 | 48 | | _memoryCache = new MemoryCache(new MemoryCacheOptions { SizeLimit = CacheSizeLimit }); |
| | | 49 | | |
| | 27 | 50 | | var apiKey = Plugin.Instance.Configuration.TmdbApiKey; |
| | 27 | 51 | | apiKey = string.IsNullOrEmpty(apiKey) ? TmdbUtils.ApiKey : apiKey; |
| | 27 | 52 | | _tmDbClient = new TMDbClient(apiKey); |
| | | 53 | | |
| | | 54 | | // Not really interested in NotFoundException |
| | 27 | 55 | | _tmDbClient.ThrowApiExceptions = false; |
| | 27 | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Gets a movie from the TMDb API based on its TMDb id. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="tmdbId">The movie's TMDb id.</param> |
| | | 62 | | /// <param name="language">The movie's language.</param> |
| | | 63 | | /// <param name="imageLanguages">A comma-separated list of image languages.</param> |
| | | 64 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 65 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 66 | | /// <returns>The TMDb movie or null if not found.</returns> |
| | | 67 | | public async Task<Movie?> GetMovieAsync(int tmdbId, string? language, string? imageLanguages, string? countryCod |
| | | 68 | | { |
| | 0 | 69 | | var key = $"movie-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 70 | | if (_memoryCache.TryGetValue(key, out Movie? movie)) |
| | | 71 | | { |
| | 0 | 72 | | return movie; |
| | | 73 | | } |
| | | 74 | | |
| | 0 | 75 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 76 | | |
| | 0 | 77 | | var extraMethods = MovieMethods.Credits | MovieMethods.Releases | MovieMethods.Images | MovieMethods.Videos; |
| | 0 | 78 | | if (!(Plugin.Instance?.Configuration.ExcludeTagsMovies).GetValueOrDefault()) |
| | | 79 | | { |
| | 0 | 80 | | extraMethods |= MovieMethods.Keywords; |
| | | 81 | | } |
| | | 82 | | |
| | 0 | 83 | | movie = await _tmDbClient.GetMovieAsync( |
| | 0 | 84 | | tmdbId, |
| | 0 | 85 | | TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 86 | | imageLanguages, |
| | 0 | 87 | | extraMethods, |
| | 0 | 88 | | cancellationToken).ConfigureAwait(false); |
| | | 89 | | |
| | 0 | 90 | | if (movie is not null) |
| | | 91 | | { |
| | 0 | 92 | | Cache(key, movie); |
| | | 93 | | } |
| | | 94 | | |
| | 0 | 95 | | return movie; |
| | 0 | 96 | | } |
| | | 97 | | |
| | | 98 | | /// <summary> |
| | | 99 | | /// Gets a collection from the TMDb API based on its TMDb id. |
| | | 100 | | /// </summary> |
| | | 101 | | /// <param name="tmdbId">The collection's TMDb id.</param> |
| | | 102 | | /// <param name="language">The collection's language.</param> |
| | | 103 | | /// <param name="imageLanguages">A comma-separated list of image languages.</param> |
| | | 104 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 105 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 106 | | /// <returns>The TMDb collection or null if not found.</returns> |
| | | 107 | | public async Task<Collection?> GetCollectionAsync(int tmdbId, string? language, string? imageLanguages, string? |
| | | 108 | | { |
| | 0 | 109 | | var key = $"collection-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 110 | | if (_memoryCache.TryGetValue(key, out Collection? collection)) |
| | | 111 | | { |
| | 0 | 112 | | return collection; |
| | | 113 | | } |
| | | 114 | | |
| | 0 | 115 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 116 | | |
| | 0 | 117 | | collection = await _tmDbClient.GetCollectionAsync( |
| | 0 | 118 | | tmdbId, |
| | 0 | 119 | | TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 120 | | imageLanguages, |
| | 0 | 121 | | CollectionMethods.Images, |
| | 0 | 122 | | cancellationToken).ConfigureAwait(false); |
| | | 123 | | |
| | 0 | 124 | | if (collection is not null) |
| | | 125 | | { |
| | 0 | 126 | | Cache(key, collection); |
| | | 127 | | } |
| | | 128 | | |
| | 0 | 129 | | return collection; |
| | 0 | 130 | | } |
| | | 131 | | |
| | | 132 | | /// <summary> |
| | | 133 | | /// Gets a tv show from the TMDb API based on its TMDb id. |
| | | 134 | | /// </summary> |
| | | 135 | | /// <param name="tmdbId">The tv show's TMDb id.</param> |
| | | 136 | | /// <param name="language">The tv show's language.</param> |
| | | 137 | | /// <param name="imageLanguages">A comma-separated list of image languages.</param> |
| | | 138 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 139 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 140 | | /// <returns>The TMDb tv show information or null if not found.</returns> |
| | | 141 | | public async Task<TvShow?> GetSeriesAsync(int tmdbId, string? language, string? imageLanguages, string? countryC |
| | | 142 | | { |
| | 0 | 143 | | var key = $"series-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 144 | | if (_memoryCache.TryGetValue(key, out TvShow? series)) |
| | | 145 | | { |
| | 0 | 146 | | return series; |
| | | 147 | | } |
| | | 148 | | |
| | 0 | 149 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 150 | | |
| | 0 | 151 | | var extraMethods = TvShowMethods.Credits | TvShowMethods.CreditsAggregate | TvShowMethods.Images | TvShowMet |
| | 0 | 152 | | if (!(Plugin.Instance?.Configuration.ExcludeTagsSeries).GetValueOrDefault()) |
| | | 153 | | { |
| | 0 | 154 | | extraMethods |= TvShowMethods.Keywords; |
| | | 155 | | } |
| | | 156 | | |
| | 0 | 157 | | series = await _tmDbClient.GetTvShowAsync( |
| | 0 | 158 | | tmdbId, |
| | 0 | 159 | | language: TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 160 | | includeImageLanguage: imageLanguages, |
| | 0 | 161 | | extraMethods: extraMethods, |
| | 0 | 162 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | | 163 | | |
| | 0 | 164 | | if (series is not null) |
| | | 165 | | { |
| | 0 | 166 | | Cache(key, series); |
| | | 167 | | } |
| | | 168 | | |
| | 0 | 169 | | return series; |
| | 0 | 170 | | } |
| | | 171 | | |
| | | 172 | | /// <summary> |
| | | 173 | | /// Gets a tv show episode group from the TMDb API based on the episode group. |
| | | 174 | | /// </summary> |
| | | 175 | | /// <param name="episodeGroupId">The Tmdb episode group.</param> |
| | | 176 | | /// <param name="seasonNumber">The season number of the episode group.</param> |
| | | 177 | | /// <param name="language">The tv show's language.</param> |
| | | 178 | | /// <param name="imageLanguages">A comma-separated list of image languages.</param> |
| | | 179 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 180 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 181 | | /// <returns>The TMDb tv show episode group information or null if not found.</returns> |
| | | 182 | | public async Task<TvGroup?> GetSeriesGroupAsync(string episodeGroupId, int seasonNumber, string? language, strin |
| | | 183 | | { |
| | 0 | 184 | | var key = $"group-{episodeGroupId}-{seasonNumber.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 185 | | if (_memoryCache.TryGetValue(key, out TvGroup? group)) |
| | | 186 | | { |
| | 0 | 187 | | return group; |
| | | 188 | | } |
| | | 189 | | |
| | 0 | 190 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 191 | | |
| | 0 | 192 | | var groups = await _tmDbClient.GetTvEpisodeGroupsAsync( |
| | 0 | 193 | | episodeGroupId, |
| | 0 | 194 | | language: TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 195 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | | 196 | | |
| | 0 | 197 | | group = groups?.Groups?.Find(s => s.Order == seasonNumber); |
| | 0 | 198 | | if (group is not null) |
| | | 199 | | { |
| | 0 | 200 | | Cache(key, group); |
| | | 201 | | } |
| | | 202 | | |
| | 0 | 203 | | return group; |
| | 0 | 204 | | } |
| | | 205 | | |
| | | 206 | | /// <summary> |
| | | 207 | | /// Gets a tv season from the TMDb API based on the tv show's TMDb id. |
| | | 208 | | /// </summary> |
| | | 209 | | /// <param name="tvShowId">The tv season's TMDb id.</param> |
| | | 210 | | /// <param name="seasonNumber">The season number.</param> |
| | | 211 | | /// <param name="language">The tv season's language.</param> |
| | | 212 | | /// <param name="imageLanguages">A comma-separated list of image languages.</param> |
| | | 213 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 214 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 215 | | /// <returns>The TMDb tv season information or null if not found.</returns> |
| | | 216 | | public async Task<TvSeason?> GetSeasonAsync(int tvShowId, int seasonNumber, string? language, string? imageLangu |
| | | 217 | | { |
| | 0 | 218 | | var key = $"season-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.Inv |
| | 0 | 219 | | if (_memoryCache.TryGetValue(key, out TvSeason? season)) |
| | | 220 | | { |
| | 0 | 221 | | return season; |
| | | 222 | | } |
| | | 223 | | |
| | 0 | 224 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 225 | | |
| | 0 | 226 | | season = await _tmDbClient.GetTvSeasonAsync( |
| | 0 | 227 | | tvShowId, |
| | 0 | 228 | | seasonNumber, |
| | 0 | 229 | | language: TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 230 | | includeImageLanguage: imageLanguages, |
| | 0 | 231 | | extraMethods: TvSeasonMethods.Credits | TvSeasonMethods.Images | TvSeasonMethods.ExternalIds | TvSeasonM |
| | 0 | 232 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | | 233 | | |
| | 0 | 234 | | if (season is not null) |
| | | 235 | | { |
| | 0 | 236 | | Cache(key, season); |
| | | 237 | | } |
| | | 238 | | |
| | 0 | 239 | | return season; |
| | 0 | 240 | | } |
| | | 241 | | |
| | | 242 | | /// <summary> |
| | | 243 | | /// Gets an episode from the TMDb API based on the tv show's TMDb id. |
| | | 244 | | /// </summary> |
| | | 245 | | /// <param name="tvShowId">The tv show's TMDb id.</param> |
| | | 246 | | /// <param name="seasonNumber">The season number.</param> |
| | | 247 | | /// <param name="episodeNumber">The episode number.</param> |
| | | 248 | | /// <param name="episodeGroup">The containing episode group.</param> |
| | | 249 | | /// <param name="language">The episode's language.</param> |
| | | 250 | | /// <param name="imageLanguages">A comma-separated list of image languages.</param> |
| | | 251 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 252 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 253 | | /// <returns>The TMDb tv episode information or null if not found.</returns> |
| | | 254 | | public async Task<TvEpisode?> GetEpisodeAsync(int tvShowId, int seasonNumber, long episodeNumber, string? episod |
| | | 255 | | { |
| | 0 | 256 | | var key = $"episode-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.In |
| | 0 | 257 | | if (_memoryCache.TryGetValue(key, out TvEpisode? episode)) |
| | | 258 | | { |
| | 0 | 259 | | return episode; |
| | | 260 | | } |
| | | 261 | | |
| | 0 | 262 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 263 | | |
| | 0 | 264 | | if (!string.IsNullOrWhiteSpace(episodeGroup)) |
| | | 265 | | { |
| | 0 | 266 | | var group = await GetSeriesGroupAsync(episodeGroup, seasonNumber, language, imageLanguages, countryCode, |
| | 0 | 267 | | var ep = group?.Episodes?.Find(e => e.Order == episodeNumber - 1); |
| | 0 | 268 | | if (ep is not null) |
| | | 269 | | { |
| | 0 | 270 | | seasonNumber = ep.SeasonNumber; |
| | 0 | 271 | | episodeNumber = ep.EpisodeNumber; |
| | | 272 | | } |
| | | 273 | | } |
| | | 274 | | |
| | 0 | 275 | | episode = await _tmDbClient.GetTvEpisodeAsync( |
| | 0 | 276 | | tvShowId, |
| | 0 | 277 | | seasonNumber, |
| | 0 | 278 | | episodeNumber, |
| | 0 | 279 | | language: TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 280 | | includeImageLanguage: imageLanguages, |
| | 0 | 281 | | extraMethods: TvEpisodeMethods.Credits | TvEpisodeMethods.Images | TvEpisodeMethods.ExternalIds | TvEpis |
| | 0 | 282 | | cancellationToken: cancellationToken).ConfigureAwait(false); |
| | | 283 | | |
| | 0 | 284 | | if (episode is not null) |
| | | 285 | | { |
| | 0 | 286 | | Cache(key, episode); |
| | | 287 | | } |
| | | 288 | | |
| | 0 | 289 | | return episode; |
| | 0 | 290 | | } |
| | | 291 | | |
| | | 292 | | /// <summary> |
| | | 293 | | /// Gets a person eg. cast or crew member from the TMDb API based on its TMDb id. |
| | | 294 | | /// </summary> |
| | | 295 | | /// <param name="personTmdbId">The person's TMDb id.</param> |
| | | 296 | | /// <param name="language">The person's language.</param> |
| | | 297 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 298 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 299 | | /// <returns>The TMDb person information or null if not found.</returns> |
| | | 300 | | public async Task<Person?> GetPersonAsync(int personTmdbId, string language, string? countryCode, CancellationTo |
| | | 301 | | { |
| | 0 | 302 | | var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 303 | | if (_memoryCache.TryGetValue(key, out Person? person)) |
| | | 304 | | { |
| | 0 | 305 | | return person; |
| | | 306 | | } |
| | | 307 | | |
| | 0 | 308 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 309 | | |
| | 0 | 310 | | person = await _tmDbClient.GetPersonAsync( |
| | 0 | 311 | | personTmdbId, |
| | 0 | 312 | | TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 313 | | PersonMethods.Images | PersonMethods.ExternalIds, |
| | 0 | 314 | | cancellationToken).ConfigureAwait(false); |
| | | 315 | | |
| | 0 | 316 | | if (person is not null) |
| | | 317 | | { |
| | 0 | 318 | | Cache(key, person); |
| | | 319 | | } |
| | | 320 | | |
| | 0 | 321 | | return person; |
| | 0 | 322 | | } |
| | | 323 | | |
| | | 324 | | /// <summary> |
| | | 325 | | /// Gets an item from the TMDb API based on its id from an external service eg. IMDb id, TvDb id. |
| | | 326 | | /// </summary> |
| | | 327 | | /// <param name="externalId">The item's external id.</param> |
| | | 328 | | /// <param name="source">The source of the id eg. IMDb.</param> |
| | | 329 | | /// <param name="language">The item's language.</param> |
| | | 330 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 331 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 332 | | /// <returns>The TMDb item or null if not found.</returns> |
| | | 333 | | public async Task<FindContainer?> FindByExternalIdAsync( |
| | | 334 | | string externalId, |
| | | 335 | | FindExternalSource source, |
| | | 336 | | string language, |
| | | 337 | | string? countryCode, |
| | | 338 | | CancellationToken cancellationToken) |
| | | 339 | | { |
| | 0 | 340 | | var key = $"find-{source.ToString()}-{externalId.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 341 | | if (_memoryCache.TryGetValue(key, out FindContainer? result)) |
| | | 342 | | { |
| | 0 | 343 | | return result; |
| | | 344 | | } |
| | | 345 | | |
| | 0 | 346 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 347 | | |
| | 0 | 348 | | result = await _tmDbClient.FindAsync( |
| | 0 | 349 | | source, |
| | 0 | 350 | | externalId, |
| | 0 | 351 | | TmdbUtils.NormalizeLanguage(language, countryCode), |
| | 0 | 352 | | cancellationToken).ConfigureAwait(false); |
| | | 353 | | |
| | 0 | 354 | | if (result is not null) |
| | | 355 | | { |
| | 0 | 356 | | Cache(key, result); |
| | | 357 | | } |
| | | 358 | | |
| | 0 | 359 | | return result; |
| | 0 | 360 | | } |
| | | 361 | | |
| | | 362 | | /// <summary> |
| | | 363 | | /// Searches for a tv show using the TMDb API based on its name. |
| | | 364 | | /// </summary> |
| | | 365 | | /// <param name="name">The name of the tv show.</param> |
| | | 366 | | /// <param name="language">The tv show's language.</param> |
| | | 367 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 368 | | /// <param name="year">The year the tv show first aired.</param> |
| | | 369 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 370 | | /// <returns>The TMDb tv show information.</returns> |
| | | 371 | | public async Task<IReadOnlyList<SearchTv>?> SearchSeriesAsync(string name, string language, string? countryCode, |
| | | 372 | | { |
| | 0 | 373 | | var key = $"searchseries-{name}-{year.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 374 | | if (_memoryCache.TryGetValue(key, out SearchContainer<SearchTv>? series) && series is not null) |
| | | 375 | | { |
| | 0 | 376 | | return series.Results; |
| | | 377 | | } |
| | | 378 | | |
| | 0 | 379 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 380 | | |
| | 0 | 381 | | var searchResults = await _tmDbClient |
| | 0 | 382 | | .SearchTvShowAsync(name, TmdbUtils.NormalizeLanguage(language, countryCode), includeAdult: Plugin.Instan |
| | 0 | 383 | | .ConfigureAwait(false); |
| | | 384 | | |
| | 0 | 385 | | if (searchResults?.Results?.Count > 0) |
| | | 386 | | { |
| | 0 | 387 | | CacheSearch(key, searchResults); |
| | | 388 | | } |
| | | 389 | | |
| | 0 | 390 | | return searchResults?.Results; |
| | 0 | 391 | | } |
| | | 392 | | |
| | | 393 | | /// <summary> |
| | | 394 | | /// Searches for a person based on their name using the TMDb API. |
| | | 395 | | /// </summary> |
| | | 396 | | /// <param name="name">The name of the person.</param> |
| | | 397 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 398 | | /// <returns>The TMDb person information.</returns> |
| | | 399 | | public async Task<IReadOnlyList<SearchPerson>?> SearchPersonAsync(string name, CancellationToken cancellationTok |
| | | 400 | | { |
| | 0 | 401 | | var key = $"searchperson-{name}"; |
| | 0 | 402 | | if (_memoryCache.TryGetValue(key, out SearchContainer<SearchPerson>? person) && person is not null) |
| | | 403 | | { |
| | 0 | 404 | | return person.Results; |
| | | 405 | | } |
| | | 406 | | |
| | 0 | 407 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 408 | | |
| | 0 | 409 | | var searchResults = await _tmDbClient |
| | 0 | 410 | | .SearchPersonAsync(name, includeAdult: Plugin.Instance.Configuration.IncludeAdult, cancellationToken: ca |
| | 0 | 411 | | .ConfigureAwait(false); |
| | | 412 | | |
| | 0 | 413 | | if (searchResults?.Results?.Count > 0) |
| | | 414 | | { |
| | 0 | 415 | | CacheSearch(key, searchResults); |
| | | 416 | | } |
| | | 417 | | |
| | 0 | 418 | | return searchResults?.Results; |
| | 0 | 419 | | } |
| | | 420 | | |
| | | 421 | | /// <summary> |
| | | 422 | | /// Searches for a movie based on its name using the TMDb API. |
| | | 423 | | /// </summary> |
| | | 424 | | /// <param name="name">The name of the movie.</param> |
| | | 425 | | /// <param name="language">The movie's language.</param> |
| | | 426 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 427 | | /// <returns>The TMDb movie information.</returns> |
| | | 428 | | public Task<IReadOnlyList<SearchMovie>?> SearchMovieAsync(string name, string language, CancellationToken cancel |
| | | 429 | | { |
| | 0 | 430 | | return SearchMovieAsync(name, 0, language, null, cancellationToken); |
| | | 431 | | } |
| | | 432 | | |
| | | 433 | | /// <summary> |
| | | 434 | | /// Searches for a movie based on its name using the TMDb API. |
| | | 435 | | /// </summary> |
| | | 436 | | /// <param name="name">The name of the movie.</param> |
| | | 437 | | /// <param name="year">The release year of the movie.</param> |
| | | 438 | | /// <param name="language">The movie's language.</param> |
| | | 439 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 440 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 441 | | /// <returns>The TMDb movie information.</returns> |
| | | 442 | | public async Task<IReadOnlyList<SearchMovie>?> SearchMovieAsync(string name, int year, string language, string? |
| | | 443 | | { |
| | 0 | 444 | | var key = $"moviesearch-{name}-{year.ToString(CultureInfo.InvariantCulture)}-{language}"; |
| | 0 | 445 | | if (_memoryCache.TryGetValue(key, out SearchContainer<SearchMovie>? movies) && movies is not null) |
| | | 446 | | { |
| | 0 | 447 | | return movies.Results; |
| | | 448 | | } |
| | | 449 | | |
| | 0 | 450 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 451 | | |
| | 0 | 452 | | var searchResults = await _tmDbClient |
| | 0 | 453 | | .SearchMovieAsync(name, TmdbUtils.NormalizeLanguage(language, countryCode), includeAdult: Plugin.Instanc |
| | 0 | 454 | | .ConfigureAwait(false); |
| | | 455 | | |
| | 0 | 456 | | if (searchResults?.Results?.Count > 0) |
| | | 457 | | { |
| | 0 | 458 | | CacheSearch(key, searchResults); |
| | | 459 | | } |
| | | 460 | | |
| | 0 | 461 | | return searchResults?.Results; |
| | 0 | 462 | | } |
| | | 463 | | |
| | | 464 | | /// <summary> |
| | | 465 | | /// Searches for a collection based on its name using the TMDb API. |
| | | 466 | | /// </summary> |
| | | 467 | | /// <param name="name">The name of the collection.</param> |
| | | 468 | | /// <param name="language">The collection's language.</param> |
| | | 469 | | /// <param name="countryCode">The country code, ISO 3166-1.</param> |
| | | 470 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 471 | | /// <returns>The TMDb collection information.</returns> |
| | | 472 | | public async Task<IReadOnlyList<SearchCollection>?> SearchCollectionAsync(string name, string language, string? |
| | | 473 | | { |
| | 0 | 474 | | var key = $"collectionsearch-{name}-{language}"; |
| | 0 | 475 | | if (_memoryCache.TryGetValue(key, out SearchContainer<SearchCollection>? collections) && collections is not |
| | | 476 | | { |
| | 0 | 477 | | return collections.Results; |
| | | 478 | | } |
| | | 479 | | |
| | 0 | 480 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 481 | | |
| | 0 | 482 | | var searchResults = await _tmDbClient |
| | 0 | 483 | | .SearchCollectionAsync(name, TmdbUtils.NormalizeLanguage(language, countryCode), cancellationToken: canc |
| | 0 | 484 | | .ConfigureAwait(false); |
| | | 485 | | |
| | 0 | 486 | | if (searchResults?.Results?.Count > 0) |
| | | 487 | | { |
| | 0 | 488 | | CacheSearch(key, searchResults); |
| | | 489 | | } |
| | | 490 | | |
| | 0 | 491 | | return searchResults?.Results; |
| | 0 | 492 | | } |
| | | 493 | | |
| | | 494 | | /// <summary> |
| | | 495 | | /// Gets a single page of recommended movies for a movie from the TMDb API. |
| | | 496 | | /// </summary> |
| | | 497 | | /// <param name="tmdbId">The TMDb id of the movie.</param> |
| | | 498 | | /// <param name="page">The page number to fetch (1-based).</param> |
| | | 499 | | /// <param name="language">The language for results.</param> |
| | | 500 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 501 | | /// <returns>A tuple containing the list of recommended movies and the total number of pages available.</returns |
| | | 502 | | public async Task<(IReadOnlyList<SearchMovie> Results, int TotalPages)> GetMovieRecommendationsPageAsync(int tmd |
| | | 503 | | { |
| | 0 | 504 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 505 | | |
| | 0 | 506 | | var searchResults = await _tmDbClient |
| | 0 | 507 | | .GetMovieRecommendationsAsync(tmdbId, language, page, cancellationToken) |
| | 0 | 508 | | .ConfigureAwait(false); |
| | | 509 | | |
| | 0 | 510 | | if (searchResults?.Results is null || searchResults.Results.Count == 0) |
| | | 511 | | { |
| | 0 | 512 | | return ([], 0); |
| | | 513 | | } |
| | | 514 | | |
| | 0 | 515 | | return (searchResults.Results, searchResults.TotalPages); |
| | 0 | 516 | | } |
| | | 517 | | |
| | | 518 | | /// <summary> |
| | | 519 | | /// Gets a single page of recommended TV shows for a series from the TMDb API. |
| | | 520 | | /// </summary> |
| | | 521 | | /// <param name="tmdbId">The TMDb id of the TV show.</param> |
| | | 522 | | /// <param name="page">The page number to fetch (1-based).</param> |
| | | 523 | | /// <param name="language">The language for results.</param> |
| | | 524 | | /// <param name="cancellationToken">The cancellation token.</param> |
| | | 525 | | /// <returns>A tuple containing the list of recommended TV shows and the total number of pages available.</retur |
| | | 526 | | public async Task<(IReadOnlyList<SearchTv> Results, int TotalPages)> GetSeriesRecommendationsPageAsync(int tmdbI |
| | | 527 | | { |
| | 0 | 528 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 529 | | |
| | 0 | 530 | | var searchResults = await _tmDbClient |
| | 0 | 531 | | .GetTvShowRecommendationsAsync(tmdbId, language, page, cancellationToken) |
| | 0 | 532 | | .ConfigureAwait(false); |
| | | 533 | | |
| | 0 | 534 | | if (searchResults?.Results is null || searchResults.Results.Count == 0) |
| | | 535 | | { |
| | 0 | 536 | | return ([], 0); |
| | | 537 | | } |
| | | 538 | | |
| | 0 | 539 | | return (searchResults.Results, searchResults.TotalPages); |
| | 0 | 540 | | } |
| | | 541 | | |
| | | 542 | | /// <summary> |
| | | 543 | | /// Handles bad path checking and builds the absolute url. |
| | | 544 | | /// </summary> |
| | | 545 | | /// <param name="size">The image size to fetch.</param> |
| | | 546 | | /// <param name="path">The relative URL of the image.</param> |
| | | 547 | | /// <returns>The absolute URL.</returns> |
| | | 548 | | private string? GetUrl(string? size, string? path) |
| | | 549 | | { |
| | 0 | 550 | | if (string.IsNullOrEmpty(path)) |
| | | 551 | | { |
| | 0 | 552 | | return null; |
| | | 553 | | } |
| | | 554 | | |
| | | 555 | | // Use the original size as default if size is null or empty to prevent malformed URLs |
| | 0 | 556 | | var imageSize = string.IsNullOrEmpty(size) ? TmdbUtils.OriginalImageSize : size; |
| | | 557 | | |
| | 0 | 558 | | return _tmDbClient.GetImageUrl(imageSize, path, true).ToString(); |
| | | 559 | | } |
| | | 560 | | |
| | | 561 | | /// <summary> |
| | | 562 | | /// Gets the absolute URL of the poster. |
| | | 563 | | /// </summary> |
| | | 564 | | /// <param name="posterPath">The relative URL of the poster.</param> |
| | | 565 | | /// <returns>The absolute URL.</returns> |
| | | 566 | | public string? GetPosterUrl(string? posterPath) |
| | | 567 | | { |
| | 0 | 568 | | return GetUrl(Plugin.Instance.Configuration.PosterSize, posterPath); |
| | | 569 | | } |
| | | 570 | | |
| | | 571 | | /// <summary> |
| | | 572 | | /// Gets the absolute URL of the profile image. |
| | | 573 | | /// </summary> |
| | | 574 | | /// <param name="actorProfilePath">The relative URL of the profile image.</param> |
| | | 575 | | /// <returns>The absolute URL.</returns> |
| | | 576 | | public string? GetProfileUrl(string? actorProfilePath) |
| | | 577 | | { |
| | 0 | 578 | | return GetUrl(Plugin.Instance.Configuration.ProfileSize, actorProfilePath); |
| | | 579 | | } |
| | | 580 | | |
| | | 581 | | /// <summary> |
| | | 582 | | /// Gets the absolute URL of an episode still. |
| | | 583 | | /// </summary> |
| | | 584 | | /// <param name="stillPath">The relative URL of the still.</param> |
| | | 585 | | /// <returns>The absolute URL.</returns> |
| | | 586 | | public string? GetStillUrl(string? stillPath) |
| | | 587 | | { |
| | 0 | 588 | | return GetUrl(Plugin.Instance.Configuration.StillSize, stillPath); |
| | | 589 | | } |
| | | 590 | | |
| | | 591 | | /// <summary> |
| | | 592 | | /// Converts poster <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. |
| | | 593 | | /// </summary> |
| | | 594 | | /// <param name="images">The input images.</param> |
| | | 595 | | /// <param name="requestLanguage">The requested language.</param> |
| | | 596 | | /// <returns>The remote images.</returns> |
| | | 597 | | public IEnumerable<RemoteImageInfo> ConvertPostersToRemoteImageInfo(IReadOnlyList<ImageData> images, string requ |
| | 0 | 598 | | => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.PosterSize, ImageType.Primary, requestLang |
| | | 599 | | |
| | | 600 | | /// <summary> |
| | | 601 | | /// Converts backdrop <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. |
| | | 602 | | /// </summary> |
| | | 603 | | /// <param name="images">The input images.</param> |
| | | 604 | | /// <param name="requestLanguage">The requested language.</param> |
| | | 605 | | /// <returns>The remote images.</returns> |
| | | 606 | | public IEnumerable<RemoteImageInfo> ConvertBackdropsToRemoteImageInfo(IReadOnlyList<ImageData> images, string re |
| | 0 | 607 | | => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.BackdropSize, ImageType.Backdrop, requestL |
| | | 608 | | |
| | | 609 | | /// <summary> |
| | | 610 | | /// Converts logo <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. |
| | | 611 | | /// </summary> |
| | | 612 | | /// <param name="images">The input images.</param> |
| | | 613 | | /// <param name="requestLanguage">The requested language.</param> |
| | | 614 | | /// <returns>The remote images.</returns> |
| | | 615 | | public IEnumerable<RemoteImageInfo> ConvertLogosToRemoteImageInfo(IReadOnlyList<ImageData> images, string reques |
| | 0 | 616 | | => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.LogoSize, ImageType.Logo, requestLanguage) |
| | | 617 | | |
| | | 618 | | /// <summary> |
| | | 619 | | /// Converts profile <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. |
| | | 620 | | /// </summary> |
| | | 621 | | /// <param name="images">The input images.</param> |
| | | 622 | | /// <param name="requestLanguage">The requested language.</param> |
| | | 623 | | /// <returns>The remote images.</returns> |
| | | 624 | | public IEnumerable<RemoteImageInfo> ConvertProfilesToRemoteImageInfo(IReadOnlyList<ImageData> images, string req |
| | 0 | 625 | | => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.ProfileSize, ImageType.Primary, requestLan |
| | | 626 | | |
| | | 627 | | /// <summary> |
| | | 628 | | /// Converts still <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. |
| | | 629 | | /// </summary> |
| | | 630 | | /// <param name="images">The input images.</param> |
| | | 631 | | /// <param name="requestLanguage">The requested language.</param> |
| | | 632 | | /// <returns>The remote images.</returns> |
| | | 633 | | public IEnumerable<RemoteImageInfo> ConvertStillsToRemoteImageInfo(IReadOnlyList<ImageData> images, string reque |
| | 0 | 634 | | => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.StillSize, ImageType.Primary, requestLangu |
| | | 635 | | |
| | | 636 | | /// <summary> |
| | | 637 | | /// Converts <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. |
| | | 638 | | /// </summary> |
| | | 639 | | /// <param name="images">The input images.</param> |
| | | 640 | | /// <param name="size">The size of the image to fetch.</param> |
| | | 641 | | /// <param name="type">The type of the image.</param> |
| | | 642 | | /// <param name="requestLanguage">The requested language.</param> |
| | | 643 | | /// <returns>The remote images.</returns> |
| | | 644 | | private IEnumerable<RemoteImageInfo> ConvertToRemoteImageInfo(IReadOnlyList<ImageData> images, string? size, Ima |
| | | 645 | | { |
| | | 646 | | // sizes provided are for original resolution, don't store them when downloading scaled images |
| | 0 | 647 | | var scaleImage = !TmdbUtils.IsOriginalImageSize(size); |
| | | 648 | | |
| | 0 | 649 | | for (var i = 0; i < images.Count; i++) |
| | | 650 | | { |
| | 0 | 651 | | var image = images[i]; |
| | | 652 | | |
| | 0 | 653 | | var imageType = type; |
| | 0 | 654 | | var language = TmdbUtils.GetImageLanguage(image.Iso_639_1, image.Iso_3166_1, requestLanguage); |
| | | 655 | | |
| | | 656 | | // Return Backdrops with a language specified (it has text) as Thumb. |
| | 0 | 657 | | if (imageType == ImageType.Backdrop && !string.IsNullOrEmpty(language)) |
| | | 658 | | { |
| | 0 | 659 | | imageType = ImageType.Thumb; |
| | | 660 | | } |
| | | 661 | | |
| | 0 | 662 | | yield return new RemoteImageInfo |
| | 0 | 663 | | { |
| | 0 | 664 | | Url = GetUrl(size, image.FilePath), |
| | 0 | 665 | | ThumbnailUrl = GetUrl(ThumbnailSizes.GetValueOrDefault(type.ToString(), string.Empty), image.FilePat |
| | 0 | 666 | | CommunityRating = image.VoteAverage, |
| | 0 | 667 | | VoteCount = image.VoteCount, |
| | 0 | 668 | | Width = scaleImage ? null : image.Width, |
| | 0 | 669 | | Height = scaleImage ? null : image.Height, |
| | 0 | 670 | | Language = language, |
| | 0 | 671 | | ProviderName = TmdbUtils.ProviderName, |
| | 0 | 672 | | Type = imageType, |
| | 0 | 673 | | RatingType = RatingType.Score |
| | 0 | 674 | | }; |
| | | 675 | | } |
| | 0 | 676 | | } |
| | | 677 | | |
| | | 678 | | private async Task EnsureClientConfigAsync() |
| | | 679 | | { |
| | 0 | 680 | | if (!_tmDbClient.HasConfig) |
| | | 681 | | { |
| | 0 | 682 | | var config = await _tmDbClient.GetConfigAsync().ConfigureAwait(false); |
| | 0 | 683 | | ValidatePreferences(config); |
| | | 684 | | } |
| | 0 | 685 | | } |
| | | 686 | | |
| | | 687 | | private static void ValidatePreferences(TMDbConfig config) |
| | | 688 | | { |
| | 0 | 689 | | var imageConfig = config.Images; |
| | 0 | 690 | | if (imageConfig is null) |
| | | 691 | | { |
| | 0 | 692 | | return; |
| | | 693 | | } |
| | | 694 | | |
| | 0 | 695 | | var pluginConfig = Plugin.Instance.Configuration; |
| | | 696 | | |
| | 0 | 697 | | if (imageConfig.PosterSizes is not null |
| | 0 | 698 | | && pluginConfig.PosterSize is not null |
| | 0 | 699 | | && !imageConfig.PosterSizes.Contains(pluginConfig.PosterSize)) |
| | | 700 | | { |
| | 0 | 701 | | pluginConfig.PosterSize = imageConfig.PosterSizes[^1]; |
| | | 702 | | } |
| | | 703 | | |
| | 0 | 704 | | if (imageConfig.BackdropSizes is not null |
| | 0 | 705 | | && pluginConfig.BackdropSize is not null |
| | 0 | 706 | | && !imageConfig.BackdropSizes.Contains(pluginConfig.BackdropSize)) |
| | | 707 | | { |
| | 0 | 708 | | pluginConfig.BackdropSize = imageConfig.BackdropSizes[^1]; |
| | | 709 | | } |
| | | 710 | | |
| | 0 | 711 | | if (imageConfig.LogoSizes is not null |
| | 0 | 712 | | && pluginConfig.LogoSize is not null |
| | 0 | 713 | | && !imageConfig.LogoSizes.Contains(pluginConfig.LogoSize)) |
| | | 714 | | { |
| | 0 | 715 | | pluginConfig.LogoSize = imageConfig.LogoSizes[^1]; |
| | | 716 | | } |
| | | 717 | | |
| | 0 | 718 | | if (imageConfig.ProfileSizes is not null |
| | 0 | 719 | | && pluginConfig.ProfileSize is not null |
| | 0 | 720 | | && !imageConfig.ProfileSizes.Contains(pluginConfig.ProfileSize)) |
| | | 721 | | { |
| | 0 | 722 | | pluginConfig.ProfileSize = imageConfig.ProfileSizes[^1]; |
| | | 723 | | } |
| | | 724 | | |
| | 0 | 725 | | if (imageConfig.StillSizes is not null |
| | 0 | 726 | | && pluginConfig.StillSize is not null |
| | 0 | 727 | | && !imageConfig.StillSizes.Contains(pluginConfig.StillSize)) |
| | | 728 | | { |
| | 0 | 729 | | pluginConfig.StillSize = imageConfig.StillSizes[^1]; |
| | | 730 | | } |
| | 0 | 731 | | } |
| | | 732 | | |
| | | 733 | | /// <summary> |
| | | 734 | | /// Gets the <see cref="TMDbClient"/> configuration. |
| | | 735 | | /// </summary> |
| | | 736 | | /// <returns>The configuration.</returns> |
| | | 737 | | public async Task<TMDbConfig> GetClientConfiguration() |
| | | 738 | | { |
| | 0 | 739 | | await EnsureClientConfigAsync().ConfigureAwait(false); |
| | | 740 | | |
| | 0 | 741 | | return _tmDbClient.Config; |
| | 0 | 742 | | } |
| | | 743 | | |
| | | 744 | | /// <summary> |
| | | 745 | | /// Stores a response under the shared expiry, weighed by what it costs to keep. |
| | | 746 | | /// </summary> |
| | | 747 | | private void Cache<T>(string key, T value) |
| | | 748 | | where T : class |
| | 0 | 749 | | => _memoryCache.Set( |
| | 0 | 750 | | key, |
| | 0 | 751 | | value, |
| | 0 | 752 | | new MemoryCacheEntryOptions |
| | 0 | 753 | | { |
| | 0 | 754 | | AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(CacheDurationInHours), |
| | 0 | 755 | | Size = EstimateSize(value) |
| | 0 | 756 | | }); |
| | | 757 | | |
| | | 758 | | /// <summary> |
| | | 759 | | /// Stores a page of search results, whose weight is simply how many there are. |
| | | 760 | | /// </summary> |
| | | 761 | | private void CacheSearch<T>(string key, SearchContainer<T> results) |
| | 0 | 762 | | => _memoryCache.Set( |
| | 0 | 763 | | key, |
| | 0 | 764 | | results, |
| | 0 | 765 | | new MemoryCacheEntryOptions |
| | 0 | 766 | | { |
| | 0 | 767 | | AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(CacheDurationInHours), |
| | 0 | 768 | | Size = 1 + Count(results.Results) |
| | 0 | 769 | | }); |
| | | 770 | | |
| | 0 | 771 | | private static long Count<T>(IReadOnlyCollection<T>? items) => items?.Count ?? 0; |
| | | 772 | | |
| | | 773 | | /// <summary> |
| | | 774 | | /// Estimates what keeping a response costs, counting the sub-records that dominate it. |
| | | 775 | | /// </summary> |
| | 0 | 776 | | private static long EstimateSize(object? value) => value switch |
| | 0 | 777 | | { |
| | 0 | 778 | | TvShow series => 1 |
| | 0 | 779 | | + Count(series.Credits?.Cast) + Count(series.Credits?.Crew) |
| | 0 | 780 | | + EstimateAggregateSize(series.AggregateCredits) |
| | 0 | 781 | | + Count(series.Seasons), |
| | 0 | 782 | | TvSeason season => 1 |
| | 0 | 783 | | + Count(season.Credits?.Cast) + Count(season.Credits?.Crew) |
| | 0 | 784 | | + Count(season.Episodes), |
| | 0 | 785 | | TvEpisode episode => 1 |
| | 0 | 786 | | + Count(episode.Credits?.Cast) + Count(episode.Credits?.Crew) |
| | 0 | 787 | | + Count(episode.Credits?.GuestStars), |
| | 0 | 788 | | Movie movie => 1 + Count(movie.Credits?.Cast) + Count(movie.Credits?.Crew), |
| | 0 | 789 | | Collection collection => 1 + Count(collection.Parts), |
| | 0 | 790 | | TvGroupCollection groups => 1 + Count(groups.Groups), |
| | 0 | 791 | | FindContainer found => 1 |
| | 0 | 792 | | + Count(found.MovieResults) + Count(found.TvResults) |
| | 0 | 793 | | + Count(found.PersonResults) + Count(found.TvEpisode) + Count(found.TvSeason), |
| | 0 | 794 | | _ => 1 |
| | 0 | 795 | | }; |
| | | 796 | | |
| | | 797 | | /// <summary> |
| | | 798 | | /// Weighs aggregate credits, where each person carries one record per episode they worked on. |
| | | 799 | | /// </summary> |
| | | 800 | | private static long EstimateAggregateSize(CreditsAggregate? credits) |
| | | 801 | | { |
| | 0 | 802 | | if (credits is null) |
| | | 803 | | { |
| | 0 | 804 | | return 0; |
| | | 805 | | } |
| | | 806 | | |
| | 0 | 807 | | var size = Count(credits.Cast) + Count(credits.Crew); |
| | | 808 | | |
| | 0 | 809 | | foreach (var cast in credits.Cast ?? []) |
| | | 810 | | { |
| | 0 | 811 | | size += Count(cast.Roles); |
| | | 812 | | } |
| | | 813 | | |
| | 0 | 814 | | foreach (var crew in credits.Crew ?? []) |
| | | 815 | | { |
| | 0 | 816 | | size += Count(crew.Jobs); |
| | | 817 | | } |
| | | 818 | | |
| | 0 | 819 | | return size; |
| | | 820 | | } |
| | | 821 | | |
| | | 822 | | /// <inheritdoc /> |
| | | 823 | | public void Dispose() |
| | | 824 | | { |
| | 27 | 825 | | Dispose(true); |
| | 27 | 826 | | GC.SuppressFinalize(this); |
| | 27 | 827 | | } |
| | | 828 | | |
| | | 829 | | /// <summary> |
| | | 830 | | /// Releases unmanaged and - optionally - managed resources. |
| | | 831 | | /// </summary> |
| | | 832 | | /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release |
| | | 833 | | protected virtual void Dispose(bool disposing) |
| | | 834 | | { |
| | 27 | 835 | | if (disposing) |
| | | 836 | | { |
| | 27 | 837 | | _memoryCache.Dispose(); |
| | 27 | 838 | | _tmDbClient?.Dispose(); |
| | | 839 | | } |
| | 27 | 840 | | } |
| | | 841 | | } |
| | | 842 | | } |