private string GetTVApiUrl(TVParameters parameters) { var builder = new StringBuilder($"discover/tv?api_key={_config[API_KEY]}&page={parameters.Page}"); if (!string.IsNullOrEmpty(parameters.SortOrder)) { builder.AppendLine($"&sort_by={parameters.SortOrder}"); } if (parameters.FirstAirYear is not 0) { builder.AppendLine($"&first_air_date_year={parameters.FirstAirYear}"); } if (!string.IsNullOrEmpty(parameters.FromFirstAirDate)) { builder.AppendLine($"&first_air_date.gte={parameters.FromFirstAirDate}"); } if (!string.IsNullOrEmpty(parameters.ToFirstAirDate)) { builder.AppendLine($"&first_air_date.lte={parameters.ToFirstAirDate}"); } if (parameters.GenreIds.Count() is not 0) { builder.AppendLine("&with_genres="); foreach (var genreId in parameters.GenreIds) { if (genreId == parameters.GenreIds.Last()) { builder.AppendLine($"{genreId}"); } else { builder.AppendLine($"{genreId},"); } } } if (parameters.Rating > 0) { builder.AppendLine($"&vote_average.gte={parameters.Rating}"); } if (parameters.Runtime > 0) { builder.AppendLine($"&with_runtime.gte={parameters.Runtime}"); } builder.AppendLine("&include_adult=false"); return(builder.ToString()); }
public async Task <TVResults> GetTVAsync(TVParameters parameters) { string url = GetTVApiUrl(parameters); var data = await _tmdbClient.GetData <TVResults>(url); string placeholderUrl = ImageHelper.GetPlaceholderImageUrl(new ImageSettings(_config[PLACEHOLDER_IMAGE_URL], 500, 750)); foreach (var tvShow in data.Results) { tvShow.Poster_Path = !string.IsNullOrEmpty(tvShow.Poster_Path) ? ImageHelper.GetImageUrl(new ImageSettings(_config[IMAGE_URL], PosterSizeType.W500, tvShow.Poster_Path)) : placeholderUrl; } return(data); }
private async Task <TVResults> FetchTVResults() { var parameters = new TVParameters { Page = Page, SortOrder = SortOrder, FirstAirYear = FirstAirYear, FromFirstAirDate = FromFirstAirDate, ToFirstAirDate = ToFirstAirDate, Rating = Rating, Runtime = Runtime }; if (SelectedGenreIds.Count() is not 0) { parameters.GenreIds = SelectedGenreIds; } var results = await DiscoverService.GetTVAsync(parameters); return(results); }