Ejemplo n.º 1
0
        public static void AutoLogin(SeDo se, Action <bool> callback, bool forceLogin = false)
        {
            TaskDo.Execute(() =>
            {
                try
                {
                    if (forceLogin)
                    {
                        se.GoToUrl("https://passport.csdn.net/account/logout");
                        Sleep(1);
                        se.GoToUrl("https://passport.csdn.net/login");
                    }
                    else
                    {
                        se.GoToUrl("https://i.csdn.net");
                    }
                    Sleep(2);
                    if (forceLogin || !se.CurUrl().StartsWith("https://i.csdn.net"))
                    {
                        if (string.IsNullOrEmpty(Form1.Instance.account) ||
                            string.IsNullOrEmpty(Form1.Instance.password))
                        {
                            throw new Exception("账号或密码为空");
                        }

                        se.FindText("帐号登录").Click();
                        Sleep(0.5f);
                        se.FindId("all").Click();
                        Sleep(0.5f);
                        se.FindId("all").SendKeys(Form1.Instance.account);
                        Sleep(0.5f);
                        se.FindClass("main-login").Click();
                        Sleep(0.5f);
                        se.FindId("password-number").Click();
                        Sleep(0.5f);
                        se.FindId("password-number").SendKeys(Form1.Instance.password);
                        Sleep(0.5f);
                        se.FindClass("main-login").Click();
                        Sleep(0.5f);
                        se.FindClass("btn btn-primary").Click();
                        Sleep(2);
                        se.GoToUrl("https://i.csdn.net");
                        Sleep(2);
                        if (se.CurUrl().StartsWith("https://i.csdn.net"))
                        {
                            callback.Invoke(true);
                        }
                        else
                        {
                            callback.Invoke(false);
                        }
                    }
                    else
                    {
                        callback.Invoke(true);
                    }
                }
                catch (Exception e)
                {
                    ALog(e.Message);
                    callback.Invoke(false);
                }
            });
        }
Ejemplo n.º 2
0
        private void Download()
        {
            if (!Validate())
            {
                Release(id);
                return;
            }
            if (IsDownloaded())
            {
                Release(id);
                return;
            }
            if (!UseSeDo())
            {
                Release(id);
                return;
            }

            // INFO
            Info("开始下载,请稍等...");


            Login.AutoLogin(se, (isLogin) =>
            {
                if (!isLogin)
                {
                    Fail("登录账号失败了  o(╥﹏╥)o");
                    Release(id);
                    return;
                }

                TaskDo.Execute(() =>
                {
                    try
                    {
                        //load
                        se.GoToUrl(url);
                        ALog("load -> " + url);
                        Sleep(3);
                        //cost
                        var downloadCost = -1;
                        var s_cost       = se.FindElement(By.XPath("//div[@class='dl_download_box dl_download_l']/label/em")).Text;
                        int.TryParse(s_cost, out downloadCost);
                        Sleep(1);
                        ALog("cost " + downloadCost);
                        if (downloadCost < 0)
                        {
                            Fail("获取下载消耗C币失败  o(╥﹏╥)o");
                            return;
                        }

                        //check cost
                        var vipBtn = se.FindClass("direct_download vip_download vip_down");
                        if (vipBtn != null)
                        {
                            ALog("click download");
                            vipBtn.Click();
                            Sleep(3);
                        }
                        else
                        {
                            ALog("click download");
                            se.FindClass("direct_download").Click();
                            Sleep(3);
                        }

                        //confirm download
                        // < !--3.当前用户已登录,非VIP用户,需积分且积分足够: 2002-- >
                        if (CheckClickPopWindow(se, "noVipEnoughP", "确认下载"))
                        {
                            ;
                        }
                        // <!--已经下载过该资源,不再扣除积分的弹框-->
                        else if (CheckClickPopWindow(se, "download", "下载"))
                        {
                            ;
                        }
                        // <!--2.当前用户已登录,VIP用户,积分不论:  2005-->
                        else if (CheckClickPopWindow(se, "vipIgnoreP", "VIP下载"))
                        {
                            ;
                        }

                        WaitForDownload(se, id);

                        string dName = GetDownloadName(id);

                        var path    = Form1.Instance.downloadDir + "/" + id + "/" + dName;
                        var desPath = GetZipPath(id);
                        if (Ziper.ZipFile(path, desPath))
                        {
                            ALog("压缩完成!");
                        }
                        else
                        {
                            Fail("压缩文件时候出错了 o(╥﹏╥)o" + id);
                        }

                        if (dName != null)
                        {
                            Success(GetDownloadName(id), id);
                        }
                        else
                        {
                            Fail("我下载到哪里去了?找不到了... " + id);
                        }
                    }
                    catch (Exception e)
                    {
                        Fail("发生什么了?" + "\n" + e.Message);
                    }
                    finally
                    {
                        Release(id);
                    }
                });
            });
        }