Exemple #1
0
        private string getMultipleMatchTitle(string content, int matchIndex)
        {
            string title = "";

            try
            {
                //first look for an exact title match
                string titlePattern = "find-title-" + (matchIndex + 1) + "/title_exact/images/b.gif.*?</td></tr></table>";
                Regex  R1           = new Regex(titlePattern,
                                                RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                if (R1.Matches(content).Count == 0)//now look for a popular match
                {
                    titlePattern = "title_popular/images/b.gif.*?<br>";
                    R1           = new Regex(titlePattern,
                                             RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
                }

                if (R1.Matches(content).Count == 0)//try a second pattern for popular match
                {
                    titlePattern = "/find-title-" + (matchIndex + 1) + "/.*?</td></tr></table>";

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

                if (R1.Matches(content).Count > 0)
                {
                    title = R1.Matches(content)[0].Value;

                    //remove the beginning link tags
                    title = title.Substring(title.IndexOf(">") + 1);

                    //remove the ending tags
                    //title = title.Substring(0, title.Length - 4);
                    title = title.Substring(0, title.IndexOf("    "));

                    title = title.Replace("</a>", "");

                    title = htmlCodes.ToText(title).Trim();
                }
            }
            catch (Exception ex)
            {
                Tools.WriteToFile(ex);
            }

            return(title);
        }
Exemple #2
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);
        }