From f80c827d7592d0ec69e08d995371c51f9f3c331a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 4 May 2013 00:15:39 -0400 Subject: [PATCH] set accept header for tmdb requests --- .../Providers/Movies/MovieDbProvider.cs | 93 ++++++++++++++++--- .../Providers/Movies/TmdbPersonProvider.cs | 27 +++++- 2 files changed, 106 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs index 6f096c668..835b36541 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs @@ -161,7 +161,14 @@ namespace MediaBrowser.Controller.Providers.Movies { try { - using (var json = await httpClient.Get(String.Format(TmdbConfigUrl, ApiKey), Current.MovieDbResourcePool, CancellationToken.None).ConfigureAwait(false)) + using (var json = await httpClient.Get(new HttpRequestOptions + { + Url = string.Format(TmdbConfigUrl, ApiKey), + CancellationToken = CancellationToken.None, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { return jsonSerializer.DeserializeFromStream(json); } @@ -246,7 +253,8 @@ namespace MediaBrowser.Controller.Providers.Movies private const string CastInfo = @"http://api.themoviedb.org/3/movie/{0}/casts?api_key={1}"; private const string ReleaseInfo = @"http://api.themoviedb.org/3/movie/{0}/releases?api_key={1}"; private const string GetImages = @"http://api.themoviedb.org/3/{2}/{0}/images?api_key={1}"; - public static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669"; + internal static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669"; + internal static string AcceptHeader = "application/json,image/*"; static readonly Regex[] NameMatches = new[] { new Regex(@"(?.*)\((?\d{4})\)"), // matches "My Movie (2001)" and gives us the name and the year @@ -504,7 +512,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url3, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -536,7 +551,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (var json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(new HttpRequestOptions + { + Url = url3, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -575,7 +597,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (var json = await HttpClient.Get(url3, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(new HttpRequestOptions + { + Url = url3, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { var response = JsonSerializer.DeserializeFromStream(json); @@ -657,7 +686,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { var movieResult = JsonSerializer.DeserializeFromStream(json); @@ -758,7 +794,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (var json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { mainResult = JsonSerializer.DeserializeFromStream(json); } @@ -790,7 +833,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { mainResult = JsonSerializer.DeserializeFromStream(json); } @@ -826,7 +876,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { cast = JsonSerializer.DeserializeFromStream(json); } @@ -853,7 +910,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { releases = JsonSerializer.DeserializeFromStream(json); } @@ -882,7 +946,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = Current.MovieDbResourcePool, + AcceptHeader = AcceptHeader + + }).ConfigureAwait(false)) { images = JsonSerializer.DeserializeFromStream(json); } diff --git a/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs b/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs index ac0bf9911..7aae0c0b9 100644 --- a/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/TmdbPersonProvider.cs @@ -163,7 +163,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = MovieDbProvider.Current.MovieDbResourcePool, + AcceptHeader = MovieDbProvider.AcceptHeader + + }).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -189,7 +196,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = MovieDbProvider.Current.MovieDbResourcePool, + AcceptHeader = MovieDbProvider.AcceptHeader + + }).ConfigureAwait(false)) { if (json != null) { @@ -267,7 +281,14 @@ namespace MediaBrowser.Controller.Providers.Movies try { - using (Stream json = await HttpClient.Get(url, MovieDbProvider.Current.MovieDbResourcePool, cancellationToken).ConfigureAwait(false)) + using (Stream json = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = MovieDbProvider.Current.MovieDbResourcePool, + AcceptHeader = MovieDbProvider.AcceptHeader + + }).ConfigureAwait(false)) { if (json != null) {