Пример #1
0
        /// <summary>
        /// find and display multiple matches
        /// </summary>
        /// <param name="matchContent"></param>
        /// <returns></returns>
        private Media displayMultipleMatches(string matchContent, bool bestMatch)
        {
            //find the imdbNumber and titles and display
            ArrayList searchResults = new ArrayList();
            string    foundImdbNum  = "";
            Media     foundMatch    = null;
            Media     selectedMedia = null;
            int       matchIndex    = 0;

            //string linkPattern = @"(<a.*?>.*?</a>)";
            string linkPattern = @"find-title-.*?/title_popular/images/b.gif.*?</td>";//popular title match
            Regex  R1          = new Regex(linkPattern,
                                           RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

            if (R1.Matches(matchContent).Count == 0)
            {
                linkPattern = @"find-title-.*?</td></tr></table>";

                R1 = new Regex(linkPattern,
                               RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            }

            if (R1.Matches(matchContent).Count == 0)
            {
                linkPattern = @"find-title-.*?<br>&#160;";

                R1 = new Regex(linkPattern,
                               RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            }

            foreach (Match match in R1.Matches(matchContent))
            {
                Media media = new Media();

                media.IMDBNum = getIMDBNum(match.Groups[0].Value);

                foundImdbNum = media.IMDBNum;

                media.Title = getMultipleMatchTitle(matchContent, matchIndex);

                if (media.Title.Trim().Length > 0)
                {
                    searchResults.Add(media);

                    if (bestMatch)
                    {
                        break;
                    }
                }

                matchIndex++;
            }

            if (bestMatch)
            {
                if (searchResults.Count > 0)
                {
                    selectedMedia = (Media)searchResults[0];

                    //get info
                    if (foundImdbNum != null && foundImdbNum.Length > 0)
                    {
                        foundMatch = getInfoByNumber(selectedMedia);
                    }
                }
            }
            else
            {
                //display results
                MultipleMatches multipleMatches = new MultipleMatches(searchResults);
                DialogResult    result          = multipleMatches.ShowDialog();

                if (result == DialogResult.OK)
                {
                    foundMatch = multipleMatches.MediaResult;
                }
            }

            return(foundMatch);
        }
Пример #2
0
        /// <summary>
        /// Retrieve fields from IMDB, run this sub before using the properites
        /// </summary>
        /// <remarks></remarks>
        public Media getInfo(Media media, bool bestMatch)
        {
            Media mediaResult = media;

            try
            {
                string    matchContent  = "";
                ArrayList searchResults = new ArrayList();

                //scrape the movie title
                _MovieTitle = getTitle(_FileContent);

                if (_MovieTitle == "IMDb Search" || _MovieTitle == "Find - IMDb")//there were multiple results
                {
                    if (bestMatch)
                    {
                        ArrayList matches = getMultipleMatchTitles(_FileContent);

                        if (matches.Count > 0)
                        {
                            string searchTitle = MediaHandler.FormatNameString(media.Title).ToLower();
                            searchTitle = searchTitle.Replace(" ", "");

                            foreach (Media foundMedia in matches)
                            {
                                //try to match the title with search string
                                string tempTitle = MediaHandler.FormatNameString(foundMedia.Title).ToLower();
                                tempTitle = tempTitle.Replace(" ", "");

                                //look for the entire title
                                if (tempTitle.Contains(searchTitle))
                                {
                                    mediaResult = foundMedia;
                                    break;
                                }
                            }

                            //didn't find match - look for half the title
                            if (mediaResult == null)
                            {
                                foreach (Media foundMedia in matches)
                                {
                                    string tempTitle = MediaHandler.FormatNameString(foundMedia.Title).ToLower();
                                    tempTitle = tempTitle.Replace(" ", "");

                                    if (tempTitle.Contains(searchTitle.Substring(0, searchTitle.Length / 2)))
                                    {
                                        mediaResult = foundMedia;
                                        break;
                                    }
                                }
                            }

                            //pick the first one since we didn't find a match
                            if (mediaResult == null)
                            {
                                mediaResult = (Media)matches[0];
                            }

                            mediaResult = getInfoByNumber(mediaResult);
                        }
                    }
                    else
                    {
                        searchResults = getMultipleMatchTitles(_FileContent);

                        //display results
                        MultipleMatches multipleMatches = new MultipleMatches(searchResults);
                        DialogResult    result          = multipleMatches.ShowDialog();
                        multipleMatches.BringToFront();

                        if (result == DialogResult.OK)
                        {
                            mediaResult = multipleMatches.MediaResult;
                        }
                    }

                    ////get exact matches
                    //string exactMatchPattern = @"Titles\ \(Exact\ Matches\).*?</p>";
                    ////string exactMatchPattern = @"title_exact.*?</td>";
                    //Regex R1 = new Regex(exactMatchPattern,
                    //    RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                    ////get popular titles
                    //string popularMatchPattern = @"Popular\ Titles.*?</p>";
                    //Regex R2 = new Regex(popularMatchPattern,
                    //    RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                    ////if(R2.Matches(_FileContent).Count > 0)
                    ////    matchContent = R2.Matches(_FileContent)[0].Value;

                    //if (R2.Matches(_FileContent).Count > 0)
                    //    searchResults.AddRange(getMultipleMatchTitles(R2.Matches(_FileContent)[0].Value,0));

                    ////if (R1.Matches(_FileContent).Count > 0)
                    ////    matchContent += R1.Matches(_FileContent)[0].Value;

                    //for (int x = 0; x < R1.Matches(_FileContent).Count; x++)
                    //    searchResults.AddRange(getMultipleMatchTitles(R1.Matches(_FileContent)[x].Value, x));



                    //if (matchContent.Trim().Length > 0)
                    //{
                    //    //display matches
                    //    mediaResult = displayMultipleMatches(matchContent, bestMatch);//the first one is the popular match
                    //}
                    //else //if (mediaResult == null)// || mediaResult.filePath == null || mediaResult.filePath.Length == 0)
                    //{
                    //    //find the results and their movie number and let user choose which is correct
                    //    string paragraphPattern = "<p>.*</p>";
                    //    R1 = new Regex(paragraphPattern,
                    //        RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                    //    if (R1.Matches(_FileContent).Count > 0)
                    //    {
                    //        //display matches
                    //        mediaResult = displayMultipleMatches(R1.Matches(_FileContent)[0].Value, bestMatch);//the first one is the popular match
                    //    }
                    //    else
                    //        _MovieTitle = "No Results";
                    //}
                }
                else
                {
                    mediaResult       = new Media();
                    mediaResult.Title = _MovieTitle;

                    //scrape the director
                    _Director            = getDirectors(_FileContent);
                    mediaResult.Director = HttpUtility.UrlDecode(HttpUtility.UrlEncode(_Director).Replace("%0a", "")).Trim();

                    //scrape release year
                    _ReleaseYear            = getReleaseYear(_FileContent);
                    mediaResult.ReleaseYear = _ReleaseYear;

                    //scrape movie genre
                    _Genre = getGenre(_FileContent);
                    mediaResult.category = _Genre;

                    //scrape movie tagline
                    _TagLine            = getTagline(_FileContent);
                    mediaResult.TagLine = HttpUtility.UrlDecode(HttpUtility.UrlEncode(_TagLine).Replace("%0a", "")).Trim();

                    //scrape movie description
                    _description            = getDescription(_FileContent);
                    mediaResult.Description = System.Web.HttpUtility.UrlDecode(System.Web.HttpUtility.UrlEncode(_description).Replace("%0a", "")).Trim();

                    //scrape rating
                    _rating            = getRating(_FileContent);
                    mediaResult.Rating = _rating;

                    //scrape rating description
                    _ratingDescription            = getRatingDescription(_FileContent);
                    mediaResult.RatingDescription = _ratingDescription;

                    //get mediaType from title
                    mediaResult.MediaType = getMediaType(media.Title);

                    if (_imdbNum != null && _imdbNum.Trim().Length > 0)
                    {
                        mediaResult.IMDBNum = _imdbNum;
                    }
                    else
                    {
                        mediaResult.IMDBNum = getIMDBNum(_FileContent);
                        _imdbNum            = mediaResult.IMDBNum;
                    }

                    mediaResult.Stars = getStars(_FileContent);

                    mediaResult.coverImage = getPhoto(mediaResult);

                    mediaResult.Goofs = HttpUtility.UrlDecode(HttpUtility.UrlEncode(getGoofs(_imdbNum)).Replace("%0a", "|")).Trim();

                    mediaResult.Trivia = HttpUtility.UrlDecode(HttpUtility.UrlEncode(getTrivia(_imdbNum)).Replace("%0a", "|")).Trim();

                    mediaResult.ShortDescription = getShortDescription(_FileContent);

                    _goofs            = mediaResult.Goofs;
                    _trivia           = mediaResult.Trivia;
                    _shortDescription = mediaResult.ShortDescription;
                    _stars            = mediaResult.Stars;
                }
            }
            catch (Exception ex)
            {
                Tools.WriteToFile(ex);
            }

            return(mediaResult);
        }