public string GetUrlContents(string url, string header, string userAgent, Functions.LogMessageDelegate LogMessage) { string result = string.Empty; IWebObjectStorage objectStorage = new WebObjectStorageFileSystem(_webObjectRoot); WebObject cached = objectStorage.GetUrlObject(url); if (cached != null) { result = cached.Content; } else { result = WebProcessor.GetUrlContents(url, header, userAgent, LogMessage); if (!Functions.IsEmptyString(result)) { cached = new WebObject() { Url = url, Content = result, MimeType = "text/html" }; objectStorage.SetUrlObject(cached); } } return(result); }
public string GetSearchResults(string term, string clientIp, int resultsPageSize, int pageToGet, Functions.LogMessageDelegate LogMessage) { string result = string.Empty; // // Docs for google search: // // https://developers.google.com/web-search/docs/reference#_intro_fonje // const string baseAddr = @"http://yboss.yahooapis.com/ysearch/web"; // // Note: Paging is supported in the request. To ponder. // const string searchModifierKeywords = "sound clips wav mp3"; int startIndex = pageToGet * resultsPageSize; string yahooSearchPhrase = string.Format("{0} {1}", term, searchModifierKeywords); // http://yboss.yahooapis.com/ysearch/web?q=ipod string searchUrl = string.Format(@"{0}?q={1}&count={2}", baseAddr, yahooSearchPhrase, resultsPageSize); if (LogMessage != null) { LogMessage(string.Format("Searching yahoo for: \"{0}\"", searchUrl)); } result = WebProcessor.GetUrlContents(BuildAuthenticatedUrl(new Uri(searchUrl)), @"referrer:http://www.otamata.com", @"OtamataSoundSearchService", LogMessage); return(result); }
/// <summary> /// Get the search results JSON data from Google /// </summary> /// <param name="term">The plain search term. Some keywords are added to get better search results.</param> /// <param name="clientIp">The client IP address</param> /// <param name="resultsPageSize">The number of results per page (8 recommended)</param> /// <param name="pageToGet">The zero-based index of the page to get</param> /// <returns>The raw JSON from Google.</returns> public string GetSearchResults(string term, string clientIp, int resultsPageSize, int pageToGet, Functions.LogMessageDelegate LogMessage) { string result = string.Empty; // // Docs for google search: // // https://developers.google.com/web-search/docs/reference#_intro_fonje // const string baseAddr = @"https://ajax.googleapis.com/ajax/services/search/web"; // // Note: Paging is supported in the request. To ponder. // const string searchModifierKeywords = "sound clips wav mp3"; int startIndex = pageToGet * resultsPageSize; string googleSearchPhrase = string.Format("{0} {1}", term, searchModifierKeywords); string searchUrl = string.Format(@"{0}?q={1}&v=1.0&userip={2}&start={3}&rsz={4}", baseAddr, googleSearchPhrase, clientIp, startIndex, resultsPageSize); if (LogMessage != null) { LogMessage(string.Format("Searching google for: \"{0}\"", searchUrl)); } result = WebProcessor.GetUrlContents(searchUrl, @"referrer:http://www.otamata.com", @"OtamataSoundSearchService", LogMessage); return(result); }
public string GetImageSearchResults(string term, string clientIp, int resultsPageSize, int pageToGet, Functions.LogMessageDelegate LogMessage) { // // Let's search for this bad boy! // string result = string.Empty; string size = "medium"; var uri = new Uri(string.Format("http://yboss.yahooapis.com/ysearch/images?dimensions={0}&q={1}", size, HttpUtility.UrlEncode(term))); string searchUrl = BuildAuthenticatedUrl(uri); result = WebProcessor.GetUrlContents(searchUrl, @"referrer:http://www.otamata.com", @"OtamataSoundSearchService", LogMessage); return(result); }