Esempio n. 1
0
        public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query)
        {
            var releases = new List <ReleaseInfo>();

            NameValueCollection qParams = new NameValueCollection();

            qParams.Add("tor[text]", query.GetQueryString());
            qParams.Add("tor[srchIn][title]", "true");
            qParams.Add("tor[srchIn][author]", "true");
            qParams.Add("tor[searchType]", "all");
            qParams.Add("tor[searchIn]", "torrents");
            qParams.Add("tor[hash]", "");
            qParams.Add("tor[sortType]", "default");
            qParams.Add("tor[startNumber]", "0");

            List <string> catList = MapTorznabCapsToTrackers(query);

            if (catList.Any())
            {
                foreach (string cat in catList)
                {
                    qParams.Add("tor[cat][]", cat);
                }
            }
            else
            {
                qParams.Add("tor[cat][]", "0");
            }

            string urlSearch = SearchUrl;

            if (qParams.Count > 0)
            {
                urlSearch += $"?{qParams.GetQueryString()}";
            }

            var response = await RequestStringWithCookiesAndRetry(urlSearch);

            try
            {
                CQ  dom  = response.Content;
                var rows = dom["table[class='newTorTable'] > tbody > tr"];

                foreach (IDomObject row in rows)
                {
                    CQ torrentData = row.OuterHTML;
                    CQ cells       = row.Cq().Find("td");

                    if (cells.Any() && torrentData.Find("a[class='directDownload']").Any())
                    {
                        string title    = torrentData.Find("a[class='title']").First().Text().Trim();
                        string author   = torrentData.Find("a[class='author']").First().Text().Trim();
                        Uri    link     = new Uri(SiteLink + torrentData.Find("a[class='directDownload']").First().Attr("href").Trim().TrimStart('/'));
                        Uri    guid     = new Uri(SiteLink + torrentData.Find("a[class='directDownload']").First().Attr("href").Trim().TrimStart('/'));
                        long   size     = ReleaseInfo.GetBytes(cells.Elements.ElementAt(4).Cq().Text().Split('[')[1].TrimEnd(']'));
                        int    seeders  = ParseUtil.CoerceInt(cells.Elements.ElementAt(6).Cq().Find("p").ElementAt(0).Cq().Text());
                        int    leechers = ParseUtil.CoerceInt(cells.Elements.ElementAt(6).Cq().Find("p").ElementAt(1).Cq().Text());

                        string   pubDateStr  = cells.Elements.ElementAt(5).Cq().Text().Split('[')[0];
                        DateTime publishDate = DateTime.Parse(pubDateStr).ToLocalTime();

                        long   category = 0;
                        string cat      = torrentData.Find("a[class='newCatLink']").First().Attr("href").Remove(0, "/tor/browse.php?tor[cat][]]=".Length);
                        long.TryParse(cat, out category);


                        var release = new ReleaseInfo();

                        release.Title           = String.IsNullOrEmpty(author) ? title : String.Format("{0} by {1}", title, author);
                        release.Guid            = guid;
                        release.Link            = link;
                        release.PublishDate     = publishDate;
                        release.Size            = size;
                        release.Description     = release.Title;
                        release.Seeders         = seeders;
                        release.Peers           = seeders + leechers;
                        release.MinimumRatio    = 1;
                        release.MinimumSeedTime = 172800;
                        release.Category        = MapTrackerCatToNewznab(category.ToString());
                        release.Comments        = guid;

                        releases.Add(release);
                    }
                }
            }
            catch (Exception ex)
            {
                OnParseError(response.Content, ex);
            }

            return(releases);
        }