Beispiel #1
0
 public override List <Img> GetImages(string pageString, IWebProxy proxy)
 {
     return(booru.GetImages(pageString, proxy));
 }
Beispiel #2
0
        public override List <Img> GetImages(string pageString, IWebProxy proxy)
        {
            List <Img> list = new List <Img>();

            //API
            if (GetAPImode(pageString) == APImode.JSON || GetAPImode(pageString) == APImode.XML)
            {
                list = booru.GetImages(pageString, proxy);
                return(list);
            }

            //Html
            if (pageString.Length < 20)
            {
                throw new Exception(pageString);
            }
            if (!pageString.Contains("<body"))
            {
                return(list);
            }
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(pageString);
            HtmlNodeCollection previewNodes = document.DocumentNode.SelectNodes("//div[@class=\"thumbnail-container\"]/div");

            if (previewNodes == null)
            {
                return(list);
            }
            foreach (HtmlNode node in previewNodes)
            {
                HtmlNode node1     = node.SelectSingleNode("./span/a");
                HtmlNode node2     = node1.SelectSingleNode("./img");
                string   detailUrl = FormattedImgUrl(node1.Attributes["href"].Value);
                string   desc      = Regex.Match(node1.InnerHtml, "(?<=title=\" ).*?(?=  score)").Value;
                Img      item      = new Img()
                {
                    Desc      = desc,
                    Tags      = desc,
                    Id        = Convert.ToInt32(Regex.Match(node1.Attributes["id"].Value, @"\d+").Value),
                    DetailUrl = detailUrl,
                    SampleUrl = node2.Attributes["src"].Value
                                //PreviewUrl = node1.InnerHtml.Substring(node1.InnerHtml.IndexOf("original=\"") + 10,
                                //        node1.InnerHtml.IndexOf("\" src") - node1.InnerHtml.IndexOf("original=\"") - 10)
                };
                item.DownloadDetail = (i, p) =>
                {
                    string       html = Sweb.Get(i.DetailUrl, p, shc);
                    HtmlDocument doc  = new HtmlDocument();
                    doc.LoadHtml(html);
                    HtmlNodeCollection liNodes = doc.DocumentNode.SelectNodes("//*[@id=\"tag-list\"]/div/li");
                    HtmlNode           imgData = doc.DocumentNode.SelectSingleNode("//*[@id=\"image\"]");
                    if (imgData != null)
                    {
                        i.Width      = Convert.ToInt32(imgData.Attributes["data-original-width"].Value);
                        i.Height     = Convert.ToInt32(imgData.Attributes["data-original-height"].Value);
                        i.PreviewUrl = imgData.Attributes["src"].Value;
                    }
                    foreach (HtmlNode n in liNodes)
                    {
                        if (n.InnerText.Contains("Posted:"))
                        {
                            i.Date = n.InnerText.Substring(n.InnerText.IndexOf("ed: ") + 3, n.InnerText.IndexOf(" by") - n.InnerText.IndexOf("d: ") - 3);
                        }
                        if (n.InnerHtml.Contains("by"))
                        {
                            i.Author = n.InnerText.Substring(n.InnerText.LastIndexOf(' ') + 1, n.InnerText.Length - n.InnerText.LastIndexOf(' ') - 1);
                        }
                        if (i.Width < 1 && n.InnerText.Contains("Size:"))
                        {
                            i.Dimension = n.InnerText.Substring(n.InnerText.LastIndexOf("Size: ") + 6);
                        }
                        if (n.InnerText.Contains("Source:"))
                        {
                            i.Source = n.InnerHtml.Contains("<a")
                                ? n.SelectSingleNode("./a").Attributes["href"].Value
                                : n.InnerText.Substring(n.InnerText.LastIndexOf("Source: ") + 8);
                        }
                        else
                        {
                            i.IsExplicit = !(n.InnerText.Contains("Rating:") && n.InnerText.Contains("Safe"));
                        }
                        if (n.InnerText.Contains("Score:"))
                        {
                            i.Score = Convert.ToInt32(n.SelectSingleNode("./span").InnerText);
                        }
                        else if (n.InnerHtml.Contains("Original i"))
                        {
                            i.OriginalUrl = i.JpegUrl = n.SelectSingleNode("./a").Attributes["href"].Value;
                        }
                    }
                };
                list.Add(item);
            }
            return(list);
        }
        public override List <Img> GetImages(string pageString, IWebProxy proxy)
        {
            List <Img> list = new List <Img>();

            //API
            if (APImode)
            {
                list = booru.GetImages(pageString, proxy);
                if (list.Count > 0)
                {
                    return(list);
                }
            }

            //Html
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(pageString);
            HtmlNodeCollection previewNodes = document.DocumentNode.SelectNodes("//div[@class=\"thumbnail-preview\"]");

            if (previewNodes == null)
            {
                return(list);
            }
            foreach (HtmlNode node in previewNodes)
            {
                HtmlNode node1     = node.SelectSingleNode("./span/a");
                HtmlNode node2     = node1.SelectSingleNode("./img");
                string   detailUrl = FormattedImgUrl(node1.Attributes["href"].Value);
                string   desc      = Regex.Match(node1.InnerHtml, "(?<=title=\" ).*?(?=  score)").Value;
                Img      item      = new Img()
                {
                    Desc       = desc,
                    Tags       = desc,
                    Id         = Convert.ToInt32(Regex.Match(node1.Attributes["id"].Value, @"\d+").Value),
                    DetailUrl  = detailUrl,
                    PreviewUrl = node2.Attributes["data-original"].Value
                                 //PreviewUrl = node1.InnerHtml.Substring(node1.InnerHtml.IndexOf("original=\"") + 10,
                                 //        node1.InnerHtml.IndexOf("\" src") - node1.InnerHtml.IndexOf("original=\"") - 10)
                };
                item.DownloadDetail = (i, p) =>
                {
                    string html = new MyWebClient {
                        Proxy = p, Encoding = Encoding.UTF8
                    }.DownloadString(i.DetailUrl);
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(html);
                    HtmlNodeCollection liNodes = doc.DocumentNode.SelectNodes("//li");
                    HtmlNode           imgData = doc.DocumentNode.SelectSingleNode("//*[@id=\"image\"]");
                    if (imgData != null)
                    {
                        i.Width     = Convert.ToInt32(imgData.Attributes["data-original-width"].Value);
                        i.Height    = Convert.ToInt32(imgData.Attributes["data-original-height"].Value);
                        i.SampleUrl = imgData.Attributes["src"].Value;
                    }
                    foreach (HtmlNode n in liNodes)
                    {
                        if (n.InnerText.Contains("Posted"))
                        {
                            i.Date = n.InnerText.Substring(n.InnerText.IndexOf("ed: ") + 3, n.InnerText.IndexOf(" by") - n.InnerText.IndexOf("d: ") - 3);
                        }
                        if (n.InnerHtml.Contains("by"))
                        {
                            i.Author = n.InnerText.Substring(n.InnerText.LastIndexOf(' ') + 1, n.InnerText.Length - n.InnerText.LastIndexOf(' ') - 1);
                        }
                        if (n.InnerText.Contains("Source"))
                        {
                            i.Source = n.SelectSingleNode("//*[@rel=\"nofollow\"]").Attributes["href"].Value;
                        }
                        if (n.InnerText.Contains("Rating") && n.InnerText.Contains("Safe"))
                        {
                            i.IsExplicit = false;
                        }
                        else if (n.InnerText.Contains("Rating"))
                        {
                            i.IsExplicit = true;
                        }
                        if (n.InnerText.Contains("Rating") && n.InnerText.Contains("Safe"))
                        {
                            i.IsExplicit = false;
                        }
                        else if (n.InnerText.Contains("Rating"))
                        {
                            i.IsExplicit = true;
                        }

                        if (n.InnerText.Contains("Score"))
                        {
                            i.Score = Convert.ToInt32(n.SelectSingleNode("./span").InnerText);
                        }
                        if (n.InnerHtml.Contains("Original"))
                        {
                            i.OriginalUrl = n.SelectSingleNode("./a").Attributes["href"].Value;
                            i.JpegUrl     = n.SelectSingleNode("./a").Attributes["href"].Value;
                        }
                    }
                };
                list.Add(item);
            }
            return(list);
        }