/// <summary> /// Cover search in IMPAwards.com through google domain search with /// movieName parameter as the search term. /// IMPAward page result is compared by IMDBid number for 100% accuracy. /// Parameter imdbMovieID must be in IMDB format (ie. tt0123456 including leading zeros). /// </summary> /// <param name="movieName"></param> /// <param name="imdbMovieID"></param> public void SearchCovers(string movieName, string imdbMovieID) { if (!Win32API.IsConnectedToInternet()) { return; } if (movieName == null) { return; } if (movieName == string.Empty) { return; } _imageList.Clear(); movieName = movieName.Replace(" ", "+"); string resultGoogle = string.Empty; string resultImpAw = string.Empty; string url = "http://www.google.com/search?as_q=" + movieName + "+poster&as_sitesearch=www.impawards.com"; IMPAwardsSearch x = new IMPAwardsSearch(); WebClient wc = new WebClient(); try { wc.Proxy.Credentials = CredentialCache.DefaultCredentials; byte[] buffer = wc.DownloadData(url); resultGoogle = Encoding.UTF8.GetString(buffer); } catch (Exception) { return; } finally { wc.Dispose(); } Match mGoogle = Regex.Match(resultGoogle, @"www.impawards.com[^""& <].*?(?<year>\d{4}/).*?html"); while (mGoogle.Success) { // We need all links on Google page not only first because it can be wrong movie // All links is checked against ttnumber so no wrong cover anymore Match mImpAw = mGoogle; // Check if /year/ is in link, if no that is no cover string year = mImpAw.Groups["year"].Value.Replace("/", ""); if (year != "") { string url2 = mImpAw.Value; url2 = "http://" + url2; try { byte[] buffer = wc.DownloadData(url2); resultImpAw = Encoding.UTF8.GetString(buffer); } catch (Exception) { return; } finally { wc.Dispose(); } // Check if IMDB number on poster page is equal to IMDB ttnumber, if not-> next link Match ttcheck = Regex.Match(resultImpAw, @"tt\d{7}"); if (ttcheck.Value != imdbMovieID) { break; } Match urlImpAw = Regex.Match(url2, @".*?\d{4}./*?"); // get main poster displayed on html-page mImpAw = Regex.Match(resultImpAw, @"posters/.*?.jpg"); if (mImpAw.Success) { // Check duplicate entries because Google page links can point to // same cover more than once so we don't need them int check = 0; foreach (string text in _imageList) { if (text == urlImpAw + mImpAw.Value) { check = 1; break; } } // No duplicates (check=0) if (check == 0) { _imageList.Add(urlImpAw + mImpAw.Value); } // get other posters displayed on this html-page as thumbs MatchCollection mcImpAw = Regex.Matches(resultImpAw, @"thumbs/imp_(?<poster>.*?.jpg)"); foreach (Match m1 in mcImpAw) { // Check duplicate entries because Google page links can point to // same cover more than once so we don't need them check = 0; foreach (string text in _imageList) { if (text == urlImpAw + "posters/" + m1.Groups["poster"]) { check = 1; break; } } if (check == 0) { _imageList.Add(urlImpAw + "posters/" + m1.Groups["poster"].Value); } } } } mGoogle = mGoogle.NextMatch(); } return; }