public async Task <Movie> GetMovieAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken) { var key = $"movie-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; if (_memoryCache.TryGetValue(key, out Movie movie)) { return(movie); } await EnsureClientConfigAsync().ConfigureAwait(false); var extraMethods = MovieMethods.Credits | MovieMethods.Releases | MovieMethods.Images | MovieMethods.Videos; if (!(Plugin.Instance?.Configuration.ExcludeTagsMovies).GetValueOrDefault()) { extraMethods |= MovieMethods.Keywords; } movie = await _tmDbClient.GetMovieAsync( tmdbId, TmdbUtils.NormalizeLanguage(language), imageLanguages, extraMethods, cancellationToken).ConfigureAwait(false); if (movie != null) { _memoryCache.Set(key, movie, TimeSpan.FromHours(CacheDurationInHours)); } return(movie); }
public async Task <Collection> GetCollectionAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken) { var key = $"collection-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; if (_memoryCache.TryGetValue(key, out Collection collection)) { return(collection); } await EnsureClientConfigAsync().ConfigureAwait(false); collection = await _tmDbClient.GetCollectionAsync( tmdbId, TmdbUtils.NormalizeLanguage(language), imageLanguages, CollectionMethods.Images, cancellationToken).ConfigureAwait(false); if (collection != null) { _memoryCache.Set(key, collection, TimeSpan.FromHours(CacheDurationInHours)); } return(collection); }
public async Task <FindContainer> FindByExternalIdAsync( string externalId, FindExternalSource source, string language, CancellationToken cancellationToken) { var key = $"find-{source.ToString()}-{externalId.ToString(CultureInfo.InvariantCulture)}-{language}"; if (_memoryCache.TryGetValue(key, out FindContainer result)) { return(result); } await EnsureClientConfigAsync().ConfigureAwait(false); result = await _tmDbClient.FindAsync( source, externalId, TmdbUtils.NormalizeLanguage(language), cancellationToken).ConfigureAwait(false); if (result != null) { _memoryCache.Set(key, result, TimeSpan.FromHours(CacheDurationInHours)); } return(result); }
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}"; if (_memoryCache.TryGetValue(key, out TvSeason season)) { return(season); } await EnsureClientConfigAsync().ConfigureAwait(false); season = await _tmDbClient.GetTvSeasonAsync( tvShowId, seasonNumber, language : TmdbUtils.NormalizeLanguage(language), includeImageLanguage : imageLanguages, extraMethods : TvSeasonMethods.Credits | TvSeasonMethods.Images | TvSeasonMethods.ExternalIds | TvSeasonMethods.Videos, cancellationToken : cancellationToken).ConfigureAwait(false); if (season != null) { _memoryCache.Set(key, season, TimeSpan.FromHours(CacheDurationInHours)); } return(season); }
public async Task <TvShow> GetSeriesAsync(int tmdbId, string language, string imageLanguages, CancellationToken cancellationToken) { var key = $"series-{tmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; if (_memoryCache.TryGetValue(key, out TvShow series)) { return(series); } await EnsureClientConfigAsync().ConfigureAwait(false); var extraMethods = TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.ExternalIds | TvShowMethods.Videos | TvShowMethods.ContentRatings | TvShowMethods.EpisodeGroups; if (!(Plugin.Instance?.Configuration.ExcludeTagsSeries).GetValueOrDefault()) { extraMethods |= TvShowMethods.Keywords; } series = await _tmDbClient.GetTvShowAsync( tmdbId, language : TmdbUtils.NormalizeLanguage(language), includeImageLanguage : imageLanguages, extraMethods : extraMethods, cancellationToken : cancellationToken).ConfigureAwait(false); if (series != null) { _memoryCache.Set(key, series, TimeSpan.FromHours(CacheDurationInHours)); } return(series); }
private async Task <TvGroupCollection> GetSeriesGroupAsync(int tvShowId, string episodeGroupId, string language, string imageLanguages, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(episodeGroupId)) { return(null); } var group = await _tmDbClient.GetTvEpisodeGroupsAsync( episodeGroupId, language : TmdbUtils.NormalizeLanguage(language), cancellationToken : cancellationToken).ConfigureAwait(false); return(group); }
private async Task <TvGroupCollection> GetSeriesGroupAsync(int tvShowId, string displayOrder, string language, string imageLanguages, CancellationToken cancellationToken) { TvGroupType?groupType = string.Equals(displayOrder, "originalAirDate", StringComparison.Ordinal) ? TvGroupType.OriginalAirDate : string.Equals(displayOrder, "absolute", StringComparison.Ordinal) ? TvGroupType.Absolute : string.Equals(displayOrder, "dvd", StringComparison.Ordinal) ? TvGroupType.DVD : string.Equals(displayOrder, "digital", StringComparison.Ordinal) ? TvGroupType.Digital : string.Equals(displayOrder, "storyArc", StringComparison.Ordinal) ? TvGroupType.StoryArc : string.Equals(displayOrder, "production", StringComparison.Ordinal) ? TvGroupType.Production : string.Equals(displayOrder, "tv", StringComparison.Ordinal) ? TvGroupType.TV : null; if (groupType == null) { return(null); } var key = $"group-{tvShowId.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}"; if (_memoryCache.TryGetValue(key, out TvGroupCollection group)) { return(group); } await EnsureClientConfigAsync().ConfigureAwait(false); var series = await GetSeriesAsync(tvShowId, language, imageLanguages, cancellationToken).ConfigureAwait(false); var episodeGroupId = series?.EpisodeGroups.Results.Find(g => g.Type == groupType)?.Id; if (episodeGroupId == null) { return(null); } group = await _tmDbClient.GetTvEpisodeGroupsAsync( episodeGroupId, language : TmdbUtils.NormalizeLanguage(language), cancellationToken : cancellationToken).ConfigureAwait(false); if (group != null) { _memoryCache.Set(key, group, TimeSpan.FromHours(CacheDurationInHours)); } return(group); }
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}"; if (_memoryCache.TryGetValue(key, out TvEpisode episode)) { return(episode); } await EnsureClientConfigAsync().ConfigureAwait(false); var group = await GetSeriesGroupAsync(tvShowId, displayOrder, language, imageLanguages, cancellationToken).ConfigureAwait(false); if (group != null) { var season = group.Groups.Find(s => s.Order == seasonNumber); // Episode order starts at 0 var ep = season?.Episodes.Find(e => e.Order == episodeNumber - 1); if (ep != null) { seasonNumber = ep.SeasonNumber; episodeNumber = ep.EpisodeNumber; } } episode = await _tmDbClient.GetTvEpisodeAsync( tvShowId, seasonNumber, episodeNumber, language : TmdbUtils.NormalizeLanguage(language), includeImageLanguage : imageLanguages, extraMethods : TvEpisodeMethods.Credits | TvEpisodeMethods.Images | TvEpisodeMethods.ExternalIds | TvEpisodeMethods.Videos, cancellationToken : cancellationToken).ConfigureAwait(false); if (episode != null) { _memoryCache.Set(key, episode, TimeSpan.FromHours(CacheDurationInHours)); } return(episode); }
public async Task <IReadOnlyList <SearchCollection> > SearchCollectionAsync(string name, string language, CancellationToken cancellationToken) { var key = $"collectionsearch-{name}-{language}"; if (_memoryCache.TryGetValue(key, out SearchContainer <SearchCollection> collections)) { return(collections.Results); } await EnsureClientConfigAsync().ConfigureAwait(false); var searchResults = await _tmDbClient .SearchCollectionAsync(name, TmdbUtils.NormalizeLanguage(language), cancellationToken : cancellationToken) .ConfigureAwait(false); if (searchResults.Results.Count > 0) { _memoryCache.Set(key, searchResults, TimeSpan.FromHours(CacheDurationInHours)); } return(searchResults.Results); }
public async Task <IReadOnlyList <SearchMovie> > SearchMovieAsync(string name, int year, string language, CancellationToken cancellationToken) { var key = $"moviesearch-{name}-{year.ToString(CultureInfo.InvariantCulture)}-{language}"; if (_memoryCache.TryGetValue(key, out SearchContainer <SearchMovie> movies)) { return(movies.Results); } await EnsureClientConfigAsync().ConfigureAwait(false); var searchResults = await _tmDbClient .SearchMovieAsync(name, TmdbUtils.NormalizeLanguage(language), includeAdult : Plugin.Instance.Configuration.IncludeAdult, year : year, cancellationToken : cancellationToken) .ConfigureAwait(false); if (searchResults.Results.Count > 0) { _memoryCache.Set(key, searchResults, TimeSpan.FromHours(CacheDurationInHours)); } return(searchResults.Results); }
public async Task <IReadOnlyList <SearchTv> > SearchSeriesAsync(string name, string language, int year = 0, CancellationToken cancellationToken = default) { var key = $"searchseries-{name}-{language}"; if (_memoryCache.TryGetValue(key, out SearchContainer <SearchTv> series)) { return(series.Results); } await EnsureClientConfigAsync().ConfigureAwait(false); var searchResults = await _tmDbClient .SearchTvShowAsync(name, TmdbUtils.NormalizeLanguage(language), includeAdult : Plugin.Instance.Configuration.IncludeAdult, firstAirDateYear : year, cancellationToken : cancellationToken) .ConfigureAwait(false); if (searchResults.Results.Count > 0) { _memoryCache.Set(key, searchResults, TimeSpan.FromHours(CacheDurationInHours)); } return(searchResults.Results); }
private void ConvertToRemoteImageInfo(List <ImageData> images, string size, ImageType type, string requestLanguage, List <RemoteImageInfo> results) { // sizes provided are for original resolution, don't store them when downloading scaled images var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase); for (var i = 0; i < images.Count; i++) { var image = images[i]; results.Add(new RemoteImageInfo { Url = GetUrl(size, image.FilePath), CommunityRating = image.VoteAverage, VoteCount = image.VoteCount, Width = scaleImage ? null : image.Width, Height = scaleImage ? null : image.Height, Language = TmdbUtils.AdjustImageLanguage(image.Iso_639_1, requestLanguage), ProviderName = TmdbUtils.ProviderName, Type = type, RatingType = RatingType.Score }); } }
public async Task <Person> GetPersonAsync(int personTmdbId, string language, CancellationToken cancellationToken) { var key = $"person-{personTmdbId.ToString(CultureInfo.InvariantCulture)}-{language}"; if (_memoryCache.TryGetValue(key, out Person person)) { return(person); } await EnsureClientConfigAsync().ConfigureAwait(false); person = await _tmDbClient.GetPersonAsync( personTmdbId, TmdbUtils.NormalizeLanguage(language), PersonMethods.TvCredits | PersonMethods.MovieCredits | PersonMethods.Images | PersonMethods.ExternalIds, cancellationToken).ConfigureAwait(false); if (person != null) { _memoryCache.Set(key, person, TimeSpan.FromHours(CacheDurationInHours)); } return(person); }