Beispiel #1
0
        private string GetPostText(HtmlNode li, IQuest quest)
        {
            // Get the primary content of the list item
            HtmlNode?primaryContent = li.GetChildWithClass("primaryContent");

            // On one branch, we can get the post text
            HtmlNode?messageContent = primaryContent?.GetChildWithClass("messageContent");
            HtmlNode?postBlock      = messageContent?.Element("article")?.Element("blockquote");

            List <string> excludedClasses = new List <string> {
                "bbCodeQuote", "messageTextEndMarker", "advbbcodebar_encadre",
                "advbbcodebar_article", "adv_tabs_wrapper", "adv_slider_wrapper"
            };

            if (quest.IgnoreSpoilers)
            {
                excludedClasses.Add("bbCodeSpoilerContainer");
            }

            // Predicate for filtering out elements that we don't want to include
            var exclusions = ForumPostTextConverter.GetClassesExclusionPredicate(excludedClasses);

            Uri host = new Uri(quest.ThreadUri.GetLeftPart(UriPartial.Authority) + "/");;

            // Get the full post text.
            return(ForumPostTextConverter.ExtractPostText(postBlock, exclusions, host));
        }
Beispiel #2
0
        private Predicate <HtmlNode> GetXenForoPredicate()
        {
            List <string> excludedClasses = new List <string> {
                "bbCodeQuote", "messageTextEndMarker", "advbbcodebar_encadre",
                "advbbcodebar_article", "adv_tabs_wrapper", "adv_slider_wrapper"
            };

            return(ForumPostTextConverter.GetClassesExclusionPredicate(excludedClasses));
        }
Beispiel #3
0
        private string GetPostText(HtmlNode article, IQuest quest)
        {
            // Predicate filtering out elements that we don't want to include
            List <string> excludedClasses = new List <string> {
                "bbCodeQuote", "messageTextEndMarker", "advbbcodebar_encadre",
                "advbbcodebar_article", "adv_tabs_wrapper", "adv_slider_wrapper"
            };

            if (quest.IgnoreSpoilers)
            {
                excludedClasses.Add("bbCodeSpoilerContainer");
            }

            var exclusions = ForumPostTextConverter.GetClassesExclusionPredicate(excludedClasses);

            var articleBody = article.GetDescendantWithClass("article", "message-body")?.GetChildWithClass("div", "bbWrapper");

            Uri host = new Uri(quest.ThreadUri.GetLeftPart(UriPartial.Authority) + "/");;

            return(ForumPostTextConverter.ExtractPostText(articleBody, exclusions, host));
        }
Beispiel #4
0
        /// <summary>
        /// Get a completed post from the provided HTML list item node.
        /// </summary>
        /// <param name="li">List item node that contains the post.</param>
        /// <returns>Returns a post object with required information.</returns>
        private Post?GetPost(HtmlNode li, IQuest quest)
        {
            if (li == null)
            {
                throw new ArgumentNullException(nameof(li));
            }

            string author;
            string id;
            string text;
            int    number;

            // Author and ID are in the basic list item attributes
            author = ForumPostTextConverter.CleanupWebString(li.GetAttributeValue("data-author", ""));
            id     = li.Id.Substring("post-".Length);

            if (AdvancedOptions.Instance.DebugMode)
            {
                author = $"{author}_{id}";
            }

            // Get the primary content of the list item
            HtmlNode?primaryContent = li.GetChildWithClass("primaryContent");

            // On one branch, we can get the post text
            HtmlNode?messageContent = primaryContent?.GetChildWithClass("messageContent");
            HtmlNode?postBlock      = messageContent?.Element("article")?.Element("blockquote");

            // Predicate filtering out elements that we don't want to include
            List <string> excludedClasses = new List <string> {
                "bbCodeQuote", "messageTextEndMarker", "advbbcodebar_encadre",
                "advbbcodebar_article", "adv_tabs_wrapper", "adv_slider_wrapper"
            };

            if (quest.IgnoreSpoilers)
            {
                excludedClasses.Add("bbCodeSpoilerContainer");
            }

            var exclusions = ForumPostTextConverter.GetClassesExclusionPredicate(excludedClasses);

            // Get the full post text.
            text = ForumPostTextConverter.ExtractPostText(postBlock, exclusions, Host);

            // On another branch of the primary content, we can get the post number.
            HtmlNode?messageMeta = primaryContent?.GetChildWithClass("messageMeta");

            // HTML parsing of the post was corrupted somehow.
            if (messageMeta == null)
            {
                return(null);
            }
            HtmlNode?publicControls = messageMeta.GetChildWithClass("publicControls");
            HtmlNode?postNumber     = publicControls?.GetChildWithClass("postNumber");

            if (postNumber == null)
            {
                return(null);
            }

            string postNumberText = postNumber.InnerText;

            // Skip the leading # character.
            if (postNumberText.StartsWith("#", StringComparison.Ordinal))
            {
                postNumberText = postNumberText.Substring(1);
            }

            number = int.Parse(postNumberText);

            Post?post;

            try
            {
                Origin origin = new Origin(author, id, number, Site, GetPermalinkForId(id));
                post = new Post(origin, text);
            }
            catch (Exception e)
            {
                Logger2.LogError(e, $"Attempt to create new post failed. (Author:{author}, ID:{id}, Number:{number}, Quest:{quest.DisplayName})");
                post = null;
            }

            return(post);
        }