public TmdbMovieProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IApplicationHost appHost) { _jsonSerializer = jsonSerializer; _httpClient = httpClient; _fileSystem = fileSystem; _configurationManager = configurationManager; _logger = logger; _localization = localization; _libraryManager = libraryManager; _appHost = appHost; Current = this; }
public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { var list = new List <RemoteImageInfo>(); var language = item.GetPreferredMetadataLanguage(); var results = await FetchImages(item, null, _jsonSerializer, cancellationToken).ConfigureAwait(false); if (results == null) { return(list); } var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original"); var supportedImages = GetSupportedImages(item).ToList(); if (supportedImages.Contains(ImageType.Primary)) { list.AddRange(GetPosters(results).Select(i => new RemoteImageInfo { Url = tmdbImageUrl + i.File_Path, CommunityRating = i.Vote_Average, VoteCount = i.Vote_Count, Width = i.Width, Height = i.Height, Language = TmdbMovieProvider.AdjustImageLanguage(i.Iso_639_1, language), ProviderName = Name, Type = ImageType.Primary, RatingType = RatingType.Score })); } if (supportedImages.Contains(ImageType.Backdrop)) { list.AddRange(GetBackdrops(results).Select(i => new RemoteImageInfo { Url = tmdbImageUrl + i.File_Path, CommunityRating = i.Vote_Average, VoteCount = i.Vote_Count, Width = i.Width, Height = i.Height, ProviderName = Name, Type = ImageType.Backdrop, RatingType = RatingType.Score })); } var isLanguageEn = string.Equals(language, "en", StringComparison.OrdinalIgnoreCase); return(list.OrderByDescending(i => { if (string.Equals(language, i.Language, StringComparison.OrdinalIgnoreCase)) { return 3; } if (!isLanguageEn) { if (string.Equals("en", i.Language, StringComparison.OrdinalIgnoreCase)) { return 2; } } if (string.IsNullOrEmpty(i.Language)) { return isLanguageEn ? 3 : 2; } return 0; }) .ThenByDescending(i => i.CommunityRating ?? 0) .ThenByDescending(i => i.VoteCount ?? 0)); }