/// <summary> /// Get media information for a movie /// </summary> /// <param name="movieName"></param> /// <returns></returns> public static List <iTunesMedia> ForMovie(string movieName) { List <iTunesMedia> retval = new List <iTunesMedia>(); try { var nvc = HttpUtility.ParseQueryString(string.Empty); // Set attributes for a movie. nvc.Add("term", movieName); nvc.Add("media", "movie"); nvc.Add("entity", "movie"); nvc.Add("limit", "5"); // Format the url string fullUrl = string.Format(_baseSearchUrl, nvc.ToString()); // Call the service and get the results: iTunesMediaResult serviceResult = fullUrl.GetJsonFromUrl().Trim().FromJson <iTunesMediaResult>(); // Set the results: retval = serviceResult.Results; } catch (Exception ex) { logger.Error("Couldn't get information for the movie", ex); } return(retval); }
/// <summary> /// Get media information for a TV show /// </summary> /// <param name="showName"></param> /// <param name="season"></param> /// <returns></returns> public static List <iTunesMedia> ForTVShow(string showName, int season) { List <iTunesMedia> retval = new List <iTunesMedia>(); var nvc = HttpUtility.ParseQueryString(string.Empty); // Include the season in the search nvc.Add("term", showName + " " + season); // Set attributes for a TV season. nvc.Add("media", "tvShow"); nvc.Add("entity", "tvSeason"); nvc.Add("limit", "5"); // Format the url string fullUrl = string.Format(_baseSearchUrl, nvc.ToString()); // Call the service and get the results: iTunesMediaResult serviceResult = fullUrl.GetJsonFromUrl().Trim().FromJson <iTunesMediaResult>(); // If we didn't get anything back, try without the season if (serviceResult.ResultCount < 1) { nvc["term"] = showName; // Format the url fullUrl = string.Format(_baseSearchUrl, nvc.ToString()); // Call the service and get the results: serviceResult = fullUrl.GetJsonFromUrl().Trim().FromJson <iTunesMediaResult>(); } // If we didn't get anything back, try without any funny characters if (serviceResult.ResultCount < 1) { // Find any funny characters... Match regMatch = Regex.Match(showName, @"[^a-zA-Z\d\s:]"); // If we found any, if (regMatch.Success) { // only take the name up to that point showName = showName.Substring(0, regMatch.Index); // Set that to be the new show name nvc["term"] = showName + " " + season; // Format the url fullUrl = string.Format(_baseSearchUrl, nvc.ToString()); // Call the service and get the results: serviceResult = fullUrl.GetJsonFromUrl().Trim().FromJson <iTunesMediaResult>(); } } // If we didn't get anything back, try without any funny characters and without the season if (serviceResult.ResultCount < 1) { // Set that to be the new show name nvc["term"] = showName; // Format the url fullUrl = string.Format(_baseSearchUrl, nvc.ToString()); // Call the service and get the results: serviceResult = fullUrl.GetJsonFromUrl().Trim().FromJson <iTunesMediaResult>(); } // Set the results: retval = serviceResult.Results; return(retval); }