diff --git a/Roadie.Api.Library/SearchEngines/Imaging/BingImageSearchEngine.cs b/Roadie.Api.Library/SearchEngines/Imaging/BingImageSearchEngine.cs index c6c5bfe..31eaba6 100644 --- a/Roadie.Api.Library/SearchEngines/Imaging/BingImageSearchEngine.cs +++ b/Roadie.Api.Library/SearchEngines/Imaging/BingImageSearchEngine.cs @@ -12,15 +12,19 @@ using System.Threading.Tasks; namespace Roadie.Library.SearchEngines.Imaging { /// - /// https://msdn.microsoft.com/en-us/library/dn760791(v=bsynd.50).aspx + /// https://docs.microsoft.com/en-us/bing/search-apis/bing-image-search/how-to/get-images /// public class BingImageSearchEngine : ImageSearchEngineBase, IBingImageSearchEngine { public override bool IsEnabled => Configuration.Integrations.BingImageSearchEngineEnabled; - public BingImageSearchEngine(IRoadieSettings configuration, ILogger logger, string requestIp = null, string referrer = null) - : base(configuration, logger, "https://api.cognitive.microsoft.com", requestIp, referrer) + public BingImageSearchEngine( + IRoadieSettings configuration, + ILogger logger, + string requestIp = null, + string referrer = null) + : base(configuration, logger, "https://api.bing.microsoft.com", requestIp, referrer) { _apiKey = configuration.Integrations.ApiKeys.FirstOrDefault(x => x.ApiName == "BingImageSearch") ?? new ApiKey(); @@ -30,7 +34,7 @@ namespace Roadie.Library.SearchEngines.Imaging { var request = new RestRequest { - Resource = "/bing/v7.0/images/search", + Resource = "/v7.0/images/search", Method = Method.Get, RequestFormat = DataFormat.Json }; @@ -51,17 +55,18 @@ namespace Roadie.Library.SearchEngines.Imaging var response = await _client.ExecuteAsync(request).ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.Unauthorized) + { throw new AuthenticationException("Api Key is not correct"); - + } if (response.ResponseStatus == ResponseStatus.Error) - throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", response.ErrorMessage, - response.Content)); + { + throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", response.ErrorMessage, response.Content)); + } if (response.Data == null || response.Data.value == null) { Logger.LogWarning("Response Is Null on PerformImageSearch [" + response.ErrorMessage + "]"); return null; } - return response.Data.value.Select(x => new ImageSearchResult { Width = (x.width ?? 0).ToString(), diff --git a/Roadie.Api.Library/SearchEngines/Imaging/ITunesSearchEngine.cs b/Roadie.Api.Library/SearchEngines/Imaging/ITunesSearchEngine.cs index fbde9c2..df52cf5 100644 --- a/Roadie.Api.Library/SearchEngines/Imaging/ITunesSearchEngine.cs +++ b/Roadie.Api.Library/SearchEngines/Imaging/ITunesSearchEngine.cs @@ -15,7 +15,12 @@ namespace Roadie.Library.SearchEngines.Imaging { public class ITunesSearchEngine : ImageSearchEngineBase, IITunesSearchEngine { - public ITunesSearchEngine(IRoadieSettings configuration, ICacheManager cacheManager, ILogger logger, string requestIp = null, string referrer = null) + public ITunesSearchEngine( + IRoadieSettings configuration, + ICacheManager cacheManager, + ILogger logger, + string requestIp = null, + string referrer = null) : base(configuration, logger, "http://itunes.apple.com", requestIp, referrer) { CacheManager = cacheManager; @@ -36,9 +41,10 @@ namespace Roadie.Library.SearchEngines.Imaging if (response.ResponseStatus == ResponseStatus.Error) { if (response.StatusCode == HttpStatusCode.Unauthorized) + { throw new AuthenticationException("Unauthorized"); - throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", - response.ErrorMessage, response.Content)); + } + throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", response.ErrorMessage, response.Content)); } var responseData = response?.Data?.results?.FirstOrDefault(); @@ -74,7 +80,7 @@ namespace Roadie.Library.SearchEngines.Imaging public override RestRequest BuildRequest(string query, int resultsCount) { - return BuildRequest(query, resultsCount, "Release"); + return BuildRequest(query, resultsCount, "album"); } #pragma warning disable CS1998 @@ -89,12 +95,16 @@ namespace Roadie.Library.SearchEngines.Imaging if (response.ResponseStatus == ResponseStatus.Error) { if (response.StatusCode == HttpStatusCode.Unauthorized) + { throw new AuthenticationException("Unauthorized"); - throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", - response.ErrorMessage, response.Content)); + } + throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", response.ErrorMessage, response.Content)); } - if (response.Data.results == null) return new ImageSearchResult[0]; + if (response.Data.results == null) + { + return new ImageSearchResult[0]; + } result = response.Data.results.Select(x => new ImageSearchResult { ArtistId = x.artistId.ToString(), @@ -120,9 +130,10 @@ namespace Roadie.Library.SearchEngines.Imaging if (response.ResponseStatus == ResponseStatus.Error) { if (response.StatusCode == HttpStatusCode.Unauthorized) + { throw new AuthenticationException("Unauthorized"); - throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", response.ErrorMessage, - response.Content)); + } + throw new Exception(string.Format("Request Error Message: {0}. Content: {1}.", response.ErrorMessage, response.Content)); } ReleaseSearchResult data = null;