Esempio n. 1
0
        public async Task <List <MagnetLinkItem> > GetMagnetLinks(string keyword, int page)
        {
            string text      = HttpUtility.UrlEncode(keyword);
            string urltoHtml = await MagnetUtility.GetUrltoHtml(string.Concat(new object[]
                                                                              { "http://www.btcherry.org/search?keyword=", text, "&p=", page }));

            string patternItem  = "<div class=\"r\">(?:.|\n)*?</div>";
            Regex  itemRegex    = new Regex(patternItem, RegexOptions.IgnoreCase);
            string patternInner = "<h5 class=\"h\">(.*)</h5>(?:.|\n)*?<span (?:.|\n)*?<span(?:.|\n)*?class=\"prop_val\">(.*?)</span>(?:.|\n)*?class=\"prop_val\">(.*?)</span>(?:.|\n)*?class=\"prop_val\">(.*?)</span>(?:.|\n)*?href=\"(.*)?&xl=(.*)&dn=(.*)\">";
            Regex  innerRegex   = new Regex(patternInner, RegexOptions.IgnoreCase);
            string patternPages = @"totalPages: (\d+)";
            Regex  pageRegex    = new Regex(patternPages);

            string pageStr = pageRegex.Match(urltoHtml).Groups[1].Value;
            int    ptmp    = 0;

            Int32.TryParse(pageStr, out ptmp);
            pageCnt[keyword] = ptmp;

            MatchCollection mc = itemRegex.Matches(urltoHtml);

            List <MagnetLinkItem> list = new List <MagnetLinkItem>(20);

            foreach (var m in mc)
            {
                var            match = innerRegex.Match(m.ToString());
                var            group = match.Groups;
                MagnetLinkItem mag   = new MagnetLinkItem();
                if (group.Count == 8)
                {
                    mag.SizeStr = group[3].Value;
                    mag.Name    = group[7].Value;
                    long ltmp = 0;
                    long.TryParse(group[6].Value, out ltmp);
                    if (ltmp == 0)
                    {
                        ltmp = MagnetUtility.StringSize2ByteSize(mag.SizeStr);
                    }
                    mag.SizeByte = ltmp;

                    mag.MagnetLink  = group[5].Value;
                    mag.CreatedTime = group[2].Value;
                    int tmp = 0;
                    Int32.TryParse(group[4].Value, out tmp);
                    mag.FileCountP = tmp;
                }
                list.Add(mag);
            }

            return(list);
        }
Esempio n. 2
0
        public async Task <int> GetResultPages(string keyword)
        {
            if (pageCnt.ContainsKey(keyword))
            {
                return(pageCnt[keyword]);
            }

            string text      = HttpUtility.UrlEncode(keyword);
            string urltoHtml = await MagnetUtility.GetUrltoHtml(string.Concat(new object[]
                                                                              { "http://www.btcherry.org/search?keyword=", text, "&p=", 1 }));

            string patternPages = @"totalPages: (\d +)";
            Regex  pageRegex    = new Regex(patternPages);
            string pageStr      = pageRegex.Match(urltoHtml).Value;
            int    ptmp         = 0;

            Int32.TryParse(pageStr, out ptmp);
            pageCnt[keyword] = ptmp;
            return(ptmp);
        }