Esempio n. 1
0
        /// <summary>
        /// 获取最新的同步信息
        /// </summary>
        /// <param name="siteIds"></param>
        /// <returns></returns>
        public static List <PTInfo> GetLastPersonInfo(IEnumerable <int> siteIds, IEnumerable <PTUser> users)
        {
            List <PTInfo>    infos  = new List <PTInfo>();
            string           sql    = string.Format("SELECT * FROM PERSONINFO A WHERE NOT EXISTS(SELECT 1 FROM PERSONINFO B WHERE A.PTSITEID = B.PTSITEID AND A.LASTSYNCDATE < B.LASTSYNCDATE) AND A.PTSITEID IN ({0}) AND ( A.NAME IN ('{1}') OR  A.USERID IN ({2}) )", string.Join(",", siteIds), string.Join("','", users.Select(x => x.UserName).Distinct()), string.Join(",", users.Select(x => x.UserId).Distinct()));
            SQLiteDataReader reader = DBUtils.ExecuteReader(sql);

            while (reader.Read())
            {
                PTInfo info = new PTInfo();
                info.Fid          = reader["FID"].TryPareValue <string>();
                info.SiteId       = (YUEnums.PTEnum)reader["PTSITEID"].TryPareValue <int>();
                info.SiteName     = reader["SITENAME"].TryPareValue <string>();
                info.UserId       = reader["USERID"].TryPareValue <int>();
                info.Url          = reader["URL"].TryPareValue <string>();
                info.Name         = reader["NAME"].TryPareValue <string>();
                info.DownSize     = reader["DOWNSIZE"].TryPareValue <string>();
                info.UpSize       = reader["UPSIZE"].TryPareValue <string>();
                info.ShareRate    = reader["SHARERATE"].TryPareValue <string>();
                info.SeedNumber   = reader["SEEDNUMBER"].TryPareValue <string>();
                info.SeedTimes    = reader["SEEDTIMES"].TryPareValue <string>();
                info.DownTimes    = reader["DOWNTIMES"].TryPareValue <string>();
                info.SeedRate     = reader["SEEDRATE"].TryPareValue <string>();
                info.Bonus        = reader["BONUS"].TryPareValue <double>();
                info.RegisterDate = reader["REGISTERDATE"].TryPareValue <DateTime>();
                info.Rank         = reader["RANK"].TryPareValue <string>();
                info.LastSyncDate = reader["LASTSYNCDATE"].TryPareValue <DateTime>();
                infos.Add(info);
            }
            return(infos);
        }
Esempio n. 2
0
        protected override void PreSetPersonInfo(HtmlDocument htmlDocument, PTInfo info)
        {
            //做种数
            var node = htmlDocument.DocumentNode.SelectSingleNode("//div[contains(concat(' ', normalize-space(@class), ' '), ' userinfo ')]//i[contains(concat(' ', normalize-space(@class), ' '), ' fa-arrow-up ')]");

            if (node != null && node.PreviousSibling != null)
            {
                info.SeedNumber = node.NextSibling.InnerText.Trim().TryPareValue <string>();
            }
        }
Esempio n. 3
0
        protected override void PreSetPersonInfo(HtmlDocument htmlDocument, PTInfo info)
        {
            //做种数
            var node = htmlDocument.DocumentNode.SelectSingleNode("//img[contains(concat(' ', normalize-space(@alt), ' '), ' 做种中 ')]");

            if (node != null && node.NextSibling != null && node.NextSibling.NextSibling != null)
            {
                info.SeedNumber = node.NextSibling.NextSibling.InnerText.Trim().TryPareValue <string>();
            }
        }
Esempio n. 4
0
        protected override void PreSetPersonInfo(HtmlDocument htmlDocument, PTInfo info)
        {
            //做种数
            string regex = "[^.0-9]";
            var    node  = htmlDocument.DocumentNode.SelectSingleNode("//img[contains(concat(' ', normalize-space(@alt), ' '), ' Torrents seeding ')]");

            if (node != null && node.NextSibling != null)
            {
                info.SeedNumber = Regex.Replace(node.NextSibling.InnerText.Trim(), regex, "", RegexOptions.IgnoreCase);
            }
        }
Esempio n. 5
0
        protected override void PreSetPersonInfo(HtmlDocument htmlDocument, PTInfo info)
        {
            //魔力值
            var node = htmlDocument.DocumentNode.SelectSingleNode("//a[contains(concat(' ', normalize-space(@href), ' '), ' mybonus.php ')]");

            if (node != null)
            {
                string regEx       = @"[^.0-9]";
                string bonusString = Regex.Replace(node.InnerText, regEx, "", RegexOptions.IgnoreCase);
                info.Bonus = bonusString.Trim().TryPareValue <double>();
            }

            //分享率
            node = htmlDocument.DocumentNode.SelectSingleNode("//font[contains(concat(' ', normalize-space(@class), ' '), ' color_uploaded ')]");
            if (node != null && node.PreviousSibling != null)
            {
                info.ShareRate = node.PreviousSibling.InnerText.Trim().TryPareValue <string>();
            }

            //上传量
            node = htmlDocument.DocumentNode.SelectSingleNode("//font[contains(concat(' ', normalize-space(@class), ' '), ' color_downloaded ')]");
            if (node != null && node.PreviousSibling != null)
            {
                info.UpSize = node.PreviousSibling.InnerText.Trim().TryPareValue <string>();
            }

            //下载量
            node = htmlDocument.DocumentNode.SelectSingleNode("//font[contains(concat(' ', normalize-space(@class), ' '), ' color_active ')]");
            if (node != null && node.PreviousSibling != null)
            {
                info.DownSize = node.PreviousSibling.InnerText.Trim().TryPareValue <string>();
            }

            //做种数
            node = htmlDocument.DocumentNode.SelectSingleNode("//img[contains(concat(' ', normalize-space(@alt), ' '), ' Torrents leeching ')]");
            if (node != null && node.PreviousSibling != null)
            {
                info.SeedNumber = node.PreviousSibling.InnerText.Trim().TryPareValue <string>();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 设置PersonInfo
        /// </summary>
        /// <param name="infoMaps"></param>
        /// <param name="nodes"></param>
        /// <param name="info"></param>
        protected override void SetPersonInfo(Dictionary <YUEnums.PersonInfoMap, int> infoMaps, HtmlNodeCollection nodes, PTInfo info)
        {
            #region Convert
            //注册日期
            var node = nodes[infoMaps[YUEnums.PersonInfoMap.RegisterDate]];
            if (node != null)
            {
                node = node.SelectSingleNode(".//span");
                if (node != null && node.Attributes.Contains("title"))
                {
                    info.RegisterDate = node.Attributes["title"].Value.TryPareValue <DateTime>();
                }
            }

            //分享率
            node = nodes[infoMaps[YUEnums.PersonInfoMap.ShareRate]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//td/font/text()");
                if (childNode != null)
                {
                    info.ShareRate = childNode.InnerText;
                }
            }

            //上传量
            node = nodes[infoMaps[YUEnums.PersonInfoMap.UpSize]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//tr[2]/td/text()[last()]");
                if (childNode != null)
                {
                    var index = childNode.InnerText.IndexOf(":");
                    if (index > -1)
                    {
                        string sizeString = childNode.InnerText.Substring(index + 1).Trim();
                        index = sizeString.IndexOf("(");
                        if (index > -1)
                        {
                            info.UpSize = sizeString.Substring(0, index).Trim();
                        }
                    }
                }
            }

            //下载量
            node = nodes[infoMaps[YUEnums.PersonInfoMap.DownSize]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//tr[2]/td[2]/text()[2]");
                if (childNode != null)
                {
                    var index = childNode.InnerText.IndexOf(":");
                    if (index > -1)
                    {
                        string sizeString = childNode.InnerText.Substring(index + 1).Trim();
                        index = sizeString.IndexOf("(");
                        if (index > -1)
                        {
                            info.DownSize = sizeString.Substring(0, index).Trim();
                        }
                    }
                }
            }

            //做种率
            node = nodes[infoMaps[YUEnums.PersonInfoMap.SeedRate]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//td/font/text()");
                if (childNode != null)
                {
                    info.SeedRate = childNode.InnerText;
                }
            }

            //做种时间
            node = nodes[infoMaps[YUEnums.PersonInfoMap.SeedTimes]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//tr[2]/td/text()[last()]");
                if (childNode != null)
                {
                    var index = childNode.InnerText.IndexOf(":");
                    if (index > -1)
                    {
                        info.SeedTimes = childNode.InnerText.Substring(index + 1).Trim();
                    }
                }
            }

            //下载时间
            node = nodes[infoMaps[YUEnums.PersonInfoMap.DownTimes]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//tr[2]/td[2]/text()[last()]");
                if (childNode != null)
                {
                    var index = childNode.InnerText.IndexOf(":");
                    if (index > -1)
                    {
                        info.DownTimes = childNode.InnerText.Substring(index + 1).Trim();
                    }
                }
            }

            //等级
            node = nodes[infoMaps[YUEnums.PersonInfoMap.Rank]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode("./img");
                if (childNode != null && childNode.Attributes.Contains("src"))
                {
                    string srcImg = childNode.Attributes["src"].Value;
                    foreach (var item in PTSiteConst.CLASSIMGS)
                    {
                        if (srcImg.IndexOf(item.Key, StringComparison.OrdinalIgnoreCase) > 0)
                        {
                            info.Rank = item.Value;
                            break;
                        }
                    }
                    if (info.Rank.IsNullOrEmptyOrWhiteSpace() && childNode.Attributes.Contains("alt"))
                    {
                        info.Rank = childNode.Attributes["alt"].Value;
                    }
                }
            }

            //积分
            node = nodes[infoMaps[YUEnums.PersonInfoMap.Bonus]];
            if (node != null)
            {
                info.Bonus = node.InnerText.TryPareValue <double>();
            }

            info.LastSyncDate = DateTime.Now;
            info.UserId       = User.UserId;
            info.SiteId       = SiteId;
            info.SiteName     = Site.Name;
            info.Name         = User.UserName;

            #endregion
        }
Esempio n. 7
0
        public override PTInfo GetPersonInfo()
        {
            PTInfo info = new PTInfo();

            if (_cookie == null || _cookie.Count <= 0)
            {
                throw new Exception(string.Format("{0} 获取Cookie信息失败,请尝试重新登录。", Site.Name));
            }

            if (User.UserId == 0)
            {
                string htmlResult = HttpUtils.GetDataGetHtml(Site.Url, _cookie);
                UpdateUserWhileChange(htmlResult, User);
                if (User.UserId == 0)
                {
                    throw new Exception(string.Format("{0} 无法获取用户ID,请尝试重新登录。", Site.Name));
                }
                else
                {
                    return(GetPersonInfo());
                }
            }
            else
            {
                string url = string.Format(Site.InfoUrl, User.UserId);
                info.Url = url;
                string htmlResult = HttpUtils.GetDataGetHtml(url, _cookie);

                if (HttpUtils.IsErrorRequest(htmlResult))
                {
                    throw new Exception(string.Format("{0} 获取用户详细信息失败,请稍后重试。原因:{1}", Site.Name, htmlResult));
                }

                HtmlDocument htmlDocument = new HtmlDocument();
                //某些站点的HTML可能不规范,导致获取信息失败,这里OptionAutoCloseOnEnd设为True
                htmlDocument.OptionAutoCloseOnEnd = true;
                htmlDocument.LoadHtml(htmlResult);//加载HTML字符串,如果是文件可以用htmlDocument.Load方法加载

                PreSetPersonInfo(htmlDocument, info);

                HtmlNodeCollection headNodes = htmlDocument.DocumentNode.SelectNodes("//table[contains(concat(' ', normalize-space(@class), ' '), ' normal_tab ')]//td[contains(concat(' ', normalize-space(@class), ' '), ' rowhead ')]");

                if (headNodes == null || headNodes.Count <= 0)
                {
                    throw new Exception(string.Format("{0} 获取用户详细信息失败,请稍后重试。", Site.Name));
                }

                //根据行头获取映射
                var infoMaps = GetInfoMaps(headNodes);

                HtmlNodeCollection nodes = htmlDocument.DocumentNode.SelectNodes("//table[contains(concat(' ', normalize-space(@class), ' '), ' normal_tab ')]//td[contains(concat(' ', normalize-space(@class), ' '), ' rowfollow ')]");
                if (nodes == null || nodes.Count <= 0)
                {
                    throw new Exception(string.Format("{0} 获取用户详细信息失败,请稍后重试。", Site.Name));
                }
                else
                {
                    SetPersonInfo(infoMaps, nodes, info);
                }

                return(info);
            }
        }
Esempio n. 8
0
        public override PTInfo GetPersonInfo()
        {
            PTInfo info = new PTInfo();

            if (User.Id == 0)
            {
                throw new Exception(string.Format("{0} 无法获取用户Id,请尝试重新登录。", SiteId));
            }
            else
            {
                string url        = string.Format(Site.InfoUrl, User.Id);
                string htmlResult = HttpUtils.GetDataGetHtml(url, _cookie);

                HtmlDocument htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(htmlResult);                                                                                                                         //加载HTML字符串,如果是文件可以用htmlDocument.Load方法加载
                HtmlNodeCollection nodes = htmlDocument.DocumentNode.SelectNodes("//table[contains(concat(' ', normalize-space(@class), ' '), ' main ')]/tr/td/table/tr"); //跟Xpath一样
                if (nodes == null || nodes.Count <= 0)
                {
                    throw new Exception(string.Format("{0} 获取用户详细信息失败,请稍后重试。", SiteId));
                }
                else
                {
                    #region Convert
                    //注册日期
                    var node = nodes[InfoMaps[YUEnums.PersonInfoMap.RegisterDate]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode("./td[2]/text()");
                        if (childNode != null)
                        {
                            info.RegisterDate = childNode.InnerText.TryPareValue <DateTime>();
                        }
                    }

                    //分享率
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.ShareRate]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode(".//td/font/text()");
                        if (childNode != null)
                        {
                            info.ShareRate = childNode.InnerText;
                        }
                    }

                    //上传量
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.UpSize]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode("./td[2]/text()");
                        if (childNode != null)
                        {
                            info.UpSize = childNode.InnerText;
                        }
                    }

                    //下载量
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.DownSize]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode("./td[2]/text()");
                        if (childNode != null)
                        {
                            info.DownSize = childNode.InnerText;
                        }
                    }

                    //做种率
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.SeedRate]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode(".//td/font/text()");
                        if (childNode != null)
                        {
                            info.SeedRate = childNode.InnerText;
                        }
                    }


                    //做种时间 下载时间
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.DownTimes]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode(".//td[2]/text()[last()]");
                        if (childNode != null)
                        {
                            string[] arr = childNode.InnerText.Split('[', ']', ',', ':', ',');
                            info.DownTimes = arr[4];
                            info.SeedTimes = arr[2];
                        }
                    }

                    //等级
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.Rank]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode("./td[2]");
                        if (childNode != null)
                        {
                            info.Rank = childNode.InnerText;
                        }
                    }

                    //积分
                    node = nodes[InfoMaps[YUEnums.PersonInfoMap.Bonus]];
                    if (node != null)
                    {
                        var childNode = node.SelectSingleNode(".//td[2]");
                        if (childNode != null)
                        {
                            info.Bonus = childNode.InnerText.TryPareValue <double>();
                        }
                    }

                    info.LastSyncDate = DateTime.Now;
                    info.Id           = User.Id;
                    info.SiteId       = SiteId;
                    info.Name         = User.UserName;

                    #endregion
                }
                return(info);
            }
        }
Esempio n. 9
0
        protected override void SetPersonInfo(Dictionary <YUEnums.PersonInfoMap, int> infoMaps, HtmlNodeCollection nodes, PTInfo info)
        {
            #region Convert
            //注册日期
            var node = nodes[infoMaps[YUEnums.PersonInfoMap.RegisterDate]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode("./text()");
                if (childNode != null)
                {
                    info.RegisterDate = childNode.InnerText.TryPareValue <DateTime>();
                }
            }

            //分享率
            node = nodes[infoMaps[YUEnums.PersonInfoMap.ShareRate]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode(".//font/text()");
                if (childNode != null)
                {
                    info.ShareRate = childNode.InnerText;
                }
            }

            //上传量
            node = nodes[infoMaps[YUEnums.PersonInfoMap.UpSize]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode("./text()");
                if (childNode != null)
                {
                    info.UpSize = childNode.InnerText;
                }
            }

            //下载量
            node = nodes[infoMaps[YUEnums.PersonInfoMap.DownSize]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode("./text()");
                if (childNode != null)
                {
                    info.DownSize = childNode.InnerText;
                }
            }

            //做种率
            node = nodes[infoMaps[YUEnums.PersonInfoMap.SeedRate]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode("./font/text()");
                if (childNode != null)
                {
                    info.SeedRate = childNode.InnerText;
                }
            }


            //做种时间 下载时间
            node = nodes[infoMaps[YUEnums.PersonInfoMap.DownTimes]];
            if (node != null)
            {
                var childNode = node.SelectSingleNode("./text()[last()]");
                if (childNode != null)
                {
                    string[] arr = childNode.InnerText.Split('[', ']', ',', ':', ',');
                    info.DownTimes = arr[4].Trim().Replace(" ", "");
                    info.SeedTimes = arr[2].Trim().Replace(" ", "");
                }
            }

            //等级
            node = nodes[infoMaps[YUEnums.PersonInfoMap.Rank]];
            if (node != null)
            {
                info.Rank = node.InnerText;
            }

            //积分
            node = nodes[infoMaps[YUEnums.PersonInfoMap.Bonus]];
            if (node != null)
            {
                info.Bonus = node.InnerText.TryPareValue <double>();
            }

            info.LastSyncDate = DateTime.Now;
            info.UserId       = User.UserId;
            info.SiteId       = SiteId;
            info.SiteName     = Site.Name;
            info.Name         = User.UserName;

            #endregion
        }
Esempio n. 10
0
        protected override void AfterSetPersonInfo(Dictionary <YUEnums.PersonInfoMap, int> infoMaps, HtmlNodeCollection nodes, PTInfo info)
        {
            //积分
            var node = nodes[infoMaps[YUEnums.PersonInfoMap.Bonus]];

            if (node != null)
            {
                node = node.SelectSingleNode(".//tr[2]/td/text()");
                string bonusString = node.InnerText;
                //移除空白之前的字符串
                bonusString = bonusString.Substring(bonusString.IndexOf(" "));
                //移除空格之后的字符串
                bonusString = bonusString.Substring(0, bonusString.IndexOf("&nbsp"));
                info.Bonus  = bonusString.Trim().TryPareValue <double>();
            }
        }