Ejemplo n.º 1
0
        public override List<Torrent> FormatData(string result)
        {
            List<Torrent> torrents = new List<Torrent>();

            var scrape = new HtmlAgilityPack.HtmlDocument();
            scrape.LoadHtml(result);
            HtmlNode docnode = scrape.DocumentNode;

            HtmlNode tableSearchResult =
                (from p in docnode.Descendants("table")
                 where p.Attributes["id"] != null && p.Attributes["id"].Value == "searchResult"
                 select p).FirstOrDefault();

            if (tableSearchResult != null)
            {
                HtmlNode[] datas =
                (from p in tableSearchResult.Descendants("tr")
                 select p).Skip(1).ToArray();

                foreach (var data in datas)
                {
                    Torrent temp = new Torrent();

                    // Get Name
                    HtmlNode name =
                       (from p in data.Descendants("a")
                        where p.Attributes["class"] != null && p.Attributes["class"].Value == "detLink"
                        select p).FirstOrDefault();
                    temp.Name = name.InnerHtml;

                    // Get Seeds/Peers
                    HtmlNode[] Connection =
                       (from p in data.Descendants("td")
                        select p).Skip(2).ToArray();
                    temp.Seed = Convert.ToInt32(Connection[0].InnerHtml);
                    temp.Leed = Convert.ToInt32(Connection[1].InnerHtml);

                    // Get Type
                    HtmlNode[] Type =
                      (from p in data.Descendants("a")
                       select p).Take(2).ToArray();
                    temp.Type = Type[0].InnerHtml + " (" + Type[1].InnerHtml + ")";

                    // Get MagnetLink
                    HtmlNode MagnetLink =
                        (from p in data.Descendants("a")
                         select p).Skip(3).First();
                    temp.MagnetLink = MagnetLink.GetAttributeValue("href", "");

                    // Get Size
                    HtmlNode Size =
                       (from p in data.Descendants("font")
                        where p.Attributes["class"] != null && p.Attributes["class"].Value == "detDesc"
                        select p).FirstOrDefault();

                    string text = Size.InnerText.Replace("&nbsp;", " ");
                    string[] substrings = text.Split(',');

                    string completeSize = substrings[1].Remove(0, 6);
                    string unit = completeSize.Substring(Math.Max(0, completeSize.Length - 3));
                    string value = completeSize.Remove(completeSize.Length - 4).Replace(".", ",");
                    temp.Size = new Size(unit, Convert.ToDouble(value));

                    // Get Date
                    try
                    {
                        string date = substrings[0].Remove(0, 9);

                        int year;
                        if (!date.Contains(":"))
                            year = Convert.ToInt32(date.Remove(0, 6));
                        else
                            year = DateTime.Now.Year;

                        temp.Date = new DateTime(year, Convert.ToInt32(date.Remove(2)), Convert.ToInt32(date.Remove(0, 3).Remove(2)));
                    }
                    catch (Exception)
                    {
                        temp.Date = new DateTime();
                    }

                    // Add Torent to list
                    torrents.Add(temp);

                }
                return torrents;
            }
            else
            {
                return torrents;        // Return empty list
            }
        }
Ejemplo n.º 2
0
        public override List<Torrent> FormatData(string result)
        {
            List<Torrent> torrents = new List<Torrent>();

            var scrape = new HtmlAgilityPack.HtmlDocument();
            scrape.LoadHtml(result);
            HtmlNode docnode = scrape.DocumentNode;

            HtmlNode tableSearchResult =
                (from p in docnode.Descendants("table")
                 where p.Attributes["class"] != null && p.Attributes["class"].Value == "data"
                 select p).FirstOrDefault();

            if (tableSearchResult != null)
            {
                HtmlNode[] datas =
                (from p in tableSearchResult.Descendants("tr")
                 select p).Skip(1).ToArray();

                foreach (var data in datas)
                {
                    Torrent temp = new Torrent();

                    // Get Name
                    HtmlNode name =
                      (from p in data.Descendants("a")
                       where p.Attributes["class"] != null && p.Attributes["class"].Value == "cellMainLink"
                       select p).FirstOrDefault();
                    temp.Name = name.InnerText;

                    // Get Seeds
                    HtmlNode Seeds =
                       (from p in data.Descendants("td")
                        where p.Attributes["class"] != null && p.Attributes["class"].Value == "green center"
                        select p).FirstOrDefault();
                    temp.Seed = Convert.ToInt32(Seeds.InnerText);

                    // Get Leech
                    HtmlNode Leech =
                       (from p in data.Descendants("td")
                        where p.Attributes["class"] != null && p.Attributes["class"].Value == "red lasttd center"
                        select p).FirstOrDefault();
                    temp.Leed = Convert.ToInt32(Leech.InnerText);

                    // Get Type
                    HtmlNode Type =
                      (from p in data.Descendants("span")
                       where p.Attributes["class"] != null && p.Attributes["class"].Value == "font11px lightgrey block"
                       select p).FirstOrDefault();

                    string tobesearched = "in";
                    temp.Type = Type.InnerText.Substring(Type.InnerText.IndexOf(tobesearched) + tobesearched.Length);

                    // Get Size
                    HtmlNode Size =
                       (from p in data.Descendants("td")
                        where p.Attributes["class"] != null && p.Attributes["class"].Value == "nobr center"
                        select p).FirstOrDefault();

                    string complete = Size.InnerText;

                    string unit = complete.Substring(Math.Max(0, complete.Length - 2));
                    string value = complete.Remove(complete.Length - 3).Replace(".", ",");
                    temp.Size = new Size(unit, Convert.ToDouble(value));

                    // Add Torent to list
                    torrents.Add(temp);
                }
            }

            return torrents;
        }