private bool IsHidden(HtmlAttributeCollection atts)
 {
     if (atts.Contains("class"))
     {
         return atts["class"].Value.Split(' ').Any(str => str == "hidden" || str.StartsWith("promo") || str.Contains("comment"));
     }
     else
         return false;
 }
Exemple #2
0
 static Item GetItemFromAttr(HtmlAttributeCollection itemAttr)
 {
     string hold = "";
     //Data quality 6 is normal, 1 is genuine
     Item tradeItem = new Item();
     tradeItem.Name = Types[Int32.Parse(itemAttr["data-quality"].Value)] +
         itemAttr["data-name"].Value;
     if (itemAttr.Contains("data-particleeffectname"))
         tradeItem.Name += " with " + itemAttr["data-particleeffectname"].Value;
     if (itemAttr.Contains("data-customname"))
         tradeItem.Name += " called " + itemAttr["data-customname"].Value;
     if (itemAttr.Contains("data-customdescription"))
         tradeItem.Name += " with description " + itemAttr["data-customdescription"].Value;
     if (itemAttr.Contains("data-tint"))
     {
         if (!Tints.TryGetValue(Int32.Parse(itemAttr["data-tint"].Value), out hold))
             tradeItem.Name += " painted a colour I haven't found yet. Contact me";
         else
             tradeItem.Name += " painted " + Tints[Int32.Parse(itemAttr["data-tint"].Value)];
     }
     tradeItem.ID = Int32.Parse(itemAttr["data-tf2itemid"].Value);
     tradeItem.Level = Int32.Parse(itemAttr["data-level"].Value);
     return tradeItem;
 }
            public bool Start(NBoilerpipeContentHandler instance, string localName, HtmlAttributeCollection atts)
            {
                try
                {
                    var alt = atts.Contains("alt") ? atts["alt"].Value : "";
                    if (alt.Length < 5)
                    {
                        alt = (atts.Contains("title") ? atts["title"].Value : alt);
                    }

                    int width = Math.Max(atts.Contains("width") ? int.Parse(atts["width"].Value.TrimEnd('p', 'x', ';')) : 0, 1);
                    int height = Math.Max(atts.Contains("height") ? int.Parse(atts["height"].Value.TrimEnd('p', 'x', ';')) : 0, 1);
                    var src = atts.Contains("src") ? atts["src"].Value : FindAlternateSrc(atts);
                    bool isWikimedia = false;
                    if (instance.inIgnorableElement <= 0 && !string.IsNullOrWhiteSpace(src) &&
                        (alt.Length > 5 || width > 400 || height > 320 || (isWikimedia = src.StartsWith("//upload.wikimedia.org"))))
                    {
                        var altWidthHeight = FindAlternateWidthHieght(src);
                        width = Math.Max(altWidthHeight.Item1, width);
                        height = Math.Max(altWidthHeight.Item2, height);

                        if (src.StartsWith("//"))
                            src = "http:" + src;

                        if (width > 400 || height > 320 || isWikimedia)
                        {
                            var tb = new Document.TextBlock("", new Sharpen.BitSet(), Math.Max((Math.Max(width, height) / 6), alt.Length), 0, 0, 0, 0, src);
                            tb.SetIsContent(true);
                            instance.textBlocks.Add(tb);
                        }
                    }
                    instance.inIgnorableElement++;
                    return true;
                }
                catch(Exception ex)
                {
                    Debug.WriteLine("during boilerpipe parsing: " + ex.ToString());
                }
                instance.inIgnorableElement++;
                return true;
            }
 /// <summary>
 /// Gets the value of an HTML attribute safely from an HTMLAttributeCollection
 /// </summary>
 /// <param name="p_hacCollection"></param>
 /// <param name="p_strItem"></param>
 /// <returns></returns>
 private static string GetHtmlAttributeValue(HtmlAttributeCollection p_hacCollection, string p_strItem)
 {
     if (p_hacCollection.Contains(p_strItem)) return ((HtmlAttribute)p_hacCollection[p_strItem]).Value;
     else return "";
 }