public async Task <IEnumerable <MovieDbTrendingItem> > GetTrendingMovies() { var url = $"https://api.themoviedb.org/3/trending/movie/week?api_key={_configuration.TmdbApiKey}"; var response = await _cachedHttpHelper.Fetch <MovieDbTrendingItemResponse>(_httpClient, url, TimeSpan.FromHours(1)); if (response == null) { return(new List <MovieDbTrendingItem>()); } var movies = response.Results; foreach (var show in movies) { show.Genres = new List <Genre>(); foreach (var genreId in show.GenreIds.Take(2)) { Genre genre = await _genreService.GetGenreById(genreId); if (genre != null) { show.Genres.Add(genre); } } } return(movies); }
private async Task <IList <Genre> > GetTvGenres() { var url = $"https://api.themoviedb.org/3/genre/tv/list?api_key={_configuration.TmdbApiKey}&language=en-US"; var response = await _cachedHttpHelper.Fetch <GenreListResponse>(_httpClient, url, TimeSpan.FromDays(10)); if (response != null) { return(response.Genres); } return(new List <Genre>()); }
public async Task <IList <TraktLastWatchedShow> > GetWatchedShows(bool forceRefresh = false) { var url = "https://api.trakt.tv/sync/watched/shows?extended=full"; var accessToken = await _authenticator.GetAccessToken(); if (accessToken == null) { return(new List <TraktLastWatchedShow>()); } var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); return(await _cachedHttpHelper.Fetch <IList <TraktLastWatchedShow> >(_httpClient, request, TimeSpan.FromHours(3), forceRefresh)); }
public async Task <TraktImage> GetImageFor(int showId) { var url = $"https://api.themoviedb.org/3/tv/{showId}/images?api_key={_configuration.TmdbApiKey}&language=en"; var showImages = await _cachedHttpHelper.Fetch <ShowImages>(_httpClient, url, TimeSpan.FromDays(5)); if (showImages == null) { return(null); } if (showImages.Posters.Count > 0) { return(new TraktImage { ImagePath = showImages.Posters.First().FilePath, TmdbId = showId }); } var backdropPath = showImages.Backdrops.FirstOrDefault()?.FilePath ?? ""; if (string.IsNullOrWhiteSpace(backdropPath)) { return(null); } return(new TraktImage { TmdbId = showId, ImagePath = backdropPath }); }
public async Task <TraktUser> GetTraktUser() { var url = "https://api.trakt.tv/users/settings"; var accessToken = await _authenticator.GetAccessToken(); if (accessToken == null) { return(null); } var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var settings = await _cachedHttpHelper.Fetch <TraktUserSettings>(_httpClient, request, TimeSpan.FromDays(1)); return(settings?.User); }