public void ShouldDownloadWithSecureMessageAsRecipient()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderSecureMessageIntegrationTests.ShouldUploadWithUseBlockchainSecureMessageAndRecipientPublicKey",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithAccountPrivateKey(AccountPrivateKey2)
                        .Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(), TestString);
            Assert.AreEqual(result.Data.ContentType, "text/plain");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "string description");
            Assert.AreEqual(result.Data.Name, "string name");
            Assert.IsNotNull(result.Data.Metadata);
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary <string, string> {
                { "keystring", "valstring" }
            })
                           .Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
Esempio n. 2
0
 public EightnovelDownloader()
 {
     CurrentParameter = new DownloadParameter
     {
         UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
     };
 }
Esempio n. 3
0
 public wfxsDownloader()
 {
     CurrentParameter = new DownloadParameter
     {
         UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36",
     };
 }
Esempio n. 4
0
        private void downloadOneFile(int fileIndex)
        {
            // check if we reach the end of the list
            if (fileIndex < this.DownloadListView.Items.Count)
            {
                // check if we need to download the file or if we need to skip it
                ListViewItem item = this.DownloadListView.Items[fileIndex];
                if (item.Checked)
                {
                    // get the URL and destination and create a parameter for async work
                    ListViewItem.ListViewSubItemCollection subitems = item.SubItems;
                    DownloadParameter parameters = new DownloadParameter();
                    parameters.url         = subitems[SUBITEM_URL_INDEX].Text;
                    parameters.destination = Application.StartupPath + subitems[SUBITEM_DEST_INDEX].Text;
                    parameters.fileIndex   = fileIndex;

                    // start the download asynchronously by giving the parameters
                    downloadBackgroundWorker.RunWorkerAsync(parameters);
                    // this method will be called again when the background worker will send it complete event
                }
                else
                {
                    // clear the download area
                    item.SubItems[SUBITEM_PERCENTAGE_INDEX].Text = string.Empty;
                    // if we need to skip this file, download the next one
                    updatePercentageOfTotalBar(fileIndex, 100);
                    downloadOneFile(fileIndex + 1);
                }
            }
            else
            {
                // if we reach the end of the list, the download is complete
                downloadComplete();
            }
        }
Esempio n. 5
0
 protected bool DownloadWithRescue(DownloadParameter p)
 {
     //下载视频
     try
     {
         this.currentParameter = p;
         if (!Network.DownloadFile(currentParameter, this.Info))                 //未出现错误即用户手动停止
         {
             return(false);
         }
     }
     catch (Exception ex)             //下载文件时出现错误
     {
         //如果此任务由一个视频组成,则报错(下载失败)
         if (Info.PartCount == 1)
         {
             throw ex;
         }
         else                 //否则继续下载,设置“部分失败”状态
         {
             Info.PartialFinished        = true;
             Info.PartialFinishedDetail += "\r\n文件: " + currentParameter.Url + " 下载失败";
         }
     }
     return(true);
 }
Esempio n. 6
0
 static void DownloadResources(string[] fileList)
 {
     //ライブラリ EXEファイルのダウンロード
     Parallel.ForEach(fileList, (string it) => {
         try {
             DownloadParameter parameter = new DownloadParameter(it);
             string savePath = Path.Combine(HomeDirectory, parameter.FileName);
             //ファイルの内容は、ファイル名=ダウンロード先のURLとする。
             //set[0]=ファイル名
             //set[1]=ダウンロードパス
             //set[2]=上書きか否か(y, n)
             Trace.WriteLine(parameter.DownloadPath);
             if (parameter.OverWritable) {
                 Downloader loader = new Downloader();
                 loader.Download(parameter.DownloadPath, savePath);
             } else {
                 if (!File.Exists(savePath)) {
                     Downloader loader = new Downloader();
                     loader.Download(parameter.DownloadPath, savePath);
                 }
             }
         } catch (Exception e) {
             Trace.WriteLine(e);
         }
     });
 }
 public Ck101Downloader()
 {
     CurrentParameter = new DownloadParameter
     {
         UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
         Timeout   = 10000
     };
 }
        public void FailWhenInvalidTransactionHash()
        {
            var param = DownloadParameter
                .Create("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
                .Build();

            UnitUnderTest.Download(param);
        }
        public void FailDownloadOnGetByteStreamWhenContentTypeIsDirectory()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadPath", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);
            result.Data.GetByteStream();
        }
        public void FailDownloadWithNoPrivateKey()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderSecureMessageIntegrationTests.ShouldUploadWithUseBlockchainSecureMessageAndRecipientPublicKey",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .Build();

            UnitUnderTest.Download(param);
        }
        public void ShouldDownloadWithVersion()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldReturnVersion", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Version, SchemaVersion);
        }
        public void FailDownloadWithWrongPrivateKey()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderSecureMessageIntegrationTests.ShouldUploadWithUseBlockchainSecureMessageAndRecipientPublicKey",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithAccountPrivateKey("7FE209FAA5DE3E1EDEBD169091145788FF7B0847AD2FE04FB7706A660BFCAF0A")
                        .Build();

            UnitUnderTest.Download(param);
        }
Esempio n. 13
0
        public void ShouldDownloadFromStorageConnection()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderStorageConnectionIntegrationTests.ShouldUploadToStorageConnection",
                                           "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Data.GetContentAsString(), TestString);
        }
 private void downloadFilePart(DownloadParameter downloadParameter)
 {
     try
     {
         var data = transferEngine.GetFile(downloadParameter.FileSearchResult.FileName, downloadParameter.Part, downloadParameter.Host);
         onFilePartDownloaded(new FilePartData(downloadParameter, data));
         //Error
     }
     catch(Exception ex)
     {
         throw new FileDownloadException(downloadParameter.Part, downloadParameter.FileSearchResult.FileName, downloadParameter.Host, ex);
     }
 }
 private void downloadFilePart(DownloadParameter downloadParameter)
 {
     try
     {
         var data = transferEngine.GetFile(downloadParameter.FileSearchResult.FileName, downloadParameter.Part, downloadParameter.Host);
         onFilePartDownloaded(new FilePartData(downloadParameter, data));
         //Error
     }
     catch (Exception ex)
     {
         throw new FileDownloadException(downloadParameter.Part, downloadParameter.FileSearchResult.FileName, downloadParameter.Host, ex);
     }
 }
        public void FailDownloadWithIncorrectPassword()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderPrivacyStrategyIntegrationTests.ShouldUploadFileWithSecuredWithPasswordPrivacyStrategy",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithPasswordPrivacy(TestPassword + "dummy")
                        .Build();

            var result = UnitUnderTest.Download(param);

            result.Data.GetByteStream().GetContentAsByteArray();
        }
        public void FailDownloadWithIncorrectNemKeys()
        {
            var transactionHash = TestDataRepository
                                  .GetData(
                "UploaderPrivacyStrategyIntegrationTests.ShouldUploadFileWithSecuredWithNemKeysPrivacyStrategy",
                "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithNemKeysPrivacy(AccountPrivateKey1, AccountPublicKey1)
                        .Build();

            var result = UnitUnderTest.Download(param);

            result.Data.GetByteStream().GetContentAsByteArray();
        }
        public void ShouldDownloadAsynchronouslyWithFailureCallback()
        {
            var param = DownloadParameter.Create("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").Build();
            var taskCompletionSource = new TaskCompletionSource <Exception>();
            var asyncCallbacks       = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                null, ex => taskCompletionSource.SetResult(ex));

            UnitUnderTest.DownloadAsync(param, asyncCallbacks);
            taskCompletionSource.Task.Wait(5000);

            var exception = taskCompletionSource.Task.Result;

            Assert.IsInstanceOfType(exception, exception.GetType());
        }
        public void ShouldDownloadAsynchronouslyWithoutCallback()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadByteArray", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var asyncTask = UnitUnderTest.DownloadAsync(param);

            while (!asyncTask.IsDone())
            {
                Thread.Sleep(50);
            }

            Assert.IsTrue(asyncTask.IsDone());
        }
Esempio n. 20
0
        private void DownloadFilePart(object downloadParameter)
        {
            DownloadParameter parameter = downloadParameter as DownloadParameter;

            try
            {
                byte[] data = transferEngine.GetFile(parameter.File, parameter.Part);
                OnFilePartDownloaded(new FilePartData(parameter, data));
            }

            catch (Exception)
            {
                throw new Exception("Download Failed!");
            }
        }
        public void ShouldDownloadWithPlainPrivacy()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderPrivacyStrategyIntegrationTests.ShouldUploadFileWithPlainPrivacyStrategy",
                                           "transactionHash");
            var param = DownloadParameter.Create(transactionHash)
                        .WithPlainPrivacy()
                        .Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.PrivacyType, (int)PrivacyType.Plain);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(),
                            new FileStream(TestTextFile, FileMode.Open, FileAccess.Read).GetContentAsString());
        }
Esempio n. 22
0
        public EynyDownloader(IPlugin plugin)
        {
            //var aes = new EncryptAes();
            //string url = string.Format("http://www02.eyny.com/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash=LiKaw&inajax=1");

            //ServicePointManager.Expect100Continue = false;

            //string postdata = "jNLWAPIFsJ0iWz7D00C09Fy1nAmQepY1y5cHlwqy0+75fQ1bfPELaZdYi/OKhAghQA0TiEVPd0wsFNCzNcVQNpqObZuZyl3DE18XX+Gwn0WBD7ARSRyDoyl8n0HpXAPIEuJgubT+X9mDY0ncZ5Tl7BnTKl0gJ79WwfclPChuPPU+S3MhyyLx2M/ugEgjDm8BrG7dRNRcXhzMBU6PhqqGLwASVuRjwg4wSvdORanK3GA=";
            //if (plugin.Configuration.ContainsKey("PostData"))
            //{
            //    if (!string.IsNullOrEmpty(plugin.Configuration["PostData"].Trim()))
            //    {
            //        postdata = plugin.Configuration["PostData"];
            //    }
            //}

            //byte[] data = Encoding.UTF8.GetBytes(aes.DecryptAes256(postdata));
            ////建立請求
            //var req = (HttpWebRequest)WebRequest.Create(url);
            //req.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)";
            //req.ContentType = "application/x-www-form-urlencoded";
            //req.ContentLength = data.Length;
            //req.Method = "POST";
            //req.CookieContainer = new CookieContainer();

            //using (var outstream = req.GetRequestStream())
            //{
            //    outstream.Write(data, 0, data.Length);
            //    outstream.Flush();
            //}
            ////關閉請求
            //req.GetResponse().Close();
            //CurrentParameter = new DownloadParameter
            //    {
            //    UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
            //    Cookies = req.CookieContainer
            //};


            CurrentParameter = new DownloadParameter
            {
                UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
                Timeout   = 10000
            };
        }
        public void ShouldDownloadAsynchronouslyWithSuccessCallback()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadByteArray", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var taskCompletionSource = new TaskCompletionSource <DownloadResult>();
            var asyncCallbacks       = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource.SetResult(downloadResult), null);

            UnitUnderTest.DownloadAsync(param, asyncCallbacks);
            taskCompletionSource.Task.Wait(5000);

            var result = taskCompletionSource.Task.Result;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Data.GetByteStream().GetContentAsByteArray());
        }
        public void ShouldDownloadString()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadString", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(), TestString);
            Assert.IsNull(result.Data.ContentType);
            Assert.IsNotNull(result.Data.DataHash);
            Assert.IsNull(result.Data.Description);
            Assert.IsNull(result.Data.Name);
            Assert.AreEqual(result.Data.Metadata.Count, 0);
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadUrlResource()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadUrlResource", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(),
                            new FileStream(TestImagePngFile, FileMode.Open, FileAccess.Read).GetContentAsString());
            Assert.IsNull(result.Data.ContentType);
            Assert.IsNotNull(result.Data.DataHash);
            Assert.IsNull(result.Data.Description);
            Assert.IsNull(result.Data.Name);
            Assert.IsNull(result.Data.Metadata);
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadFilesAsZipWithCompleteDetails()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadFilesAsZipWithCompleteDetails", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.IsNotNull(result.Data.GetByteStream().GetContentAsByteArray());
            Assert.AreEqual(result.Data.ContentType, "application/zip");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "zip description");
            Assert.AreEqual(result.Data.Name, "zip name");
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary<string, string> {{"zipkey", "zipvalue"}}).Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadUrlResourceWithCompleteDetails()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadUrlResourceWithCompleteDetails", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(),
                new FileStream(TestImagePngFile, FileMode.Open, FileAccess.Read).GetContentAsString());
            Assert.AreEqual(result.Data.ContentType, "image/png");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "url description");
            Assert.AreEqual(result.Data.Name, "url name");
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary<string, string> {{"urlkey", "urlval"}}).Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadStringWithCompleteDetails()
        {
            var transactionHash = TestDataRepository
                .GetData("UploaderIntegrationTests.ShouldUploadStringWithCompleteDetails", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var result = UnitUnderTest.Download(param);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.TransactionHash, transactionHash);
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(result.Data.GetByteStream().GetContentAsString(), TestString);
            Assert.AreEqual(result.Data.ContentType, "text/plain");
            Assert.IsNotNull(result.Data.DataHash);
            Assert.AreEqual(result.Data.Description, "string description");
            Assert.AreEqual(result.Data.Name, "string name");
            Assert.AreEqual(result.Data.Metadata.Count, 1);
            Assert.IsFalse(result.Data.Metadata.Except(new Dictionary<string, string> {{"keystring", "valstring"}})
                .Any());
            Assert.IsNotNull(result.Data.Timestamp);
        }
        public void ShouldDownloadMultipleRequestsAsynchronously()
        {
            var transactionHash = TestDataRepository
                                  .GetData("UploaderIntegrationTests.ShouldUploadByteArray", "transactionHash");
            var param = DownloadParameter.Create(transactionHash).Build();

            var taskCompletionSource1 = new TaskCompletionSource <DownloadResult>();
            var taskCompletionSource2 = new TaskCompletionSource <DownloadResult>();
            var taskCompletionSource3 = new TaskCompletionSource <DownloadResult>();
            var asyncCallbacks1       = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource1.SetResult(downloadResult), null);

            var asyncCallbacks2 = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource2.SetResult(downloadResult), null);

            var asyncCallbacks3 = AsyncCallbacks <DownloadResult> .Create <DownloadResult>(
                downloadResult => taskCompletionSource3.SetResult(downloadResult), null);

            UnitUnderTest.DownloadAsync(param, asyncCallbacks1);
            UnitUnderTest.DownloadAsync(param, asyncCallbacks2);
            UnitUnderTest.DownloadAsync(param, asyncCallbacks3);
            taskCompletionSource1.Task.Wait(5000);
            taskCompletionSource2.Task.Wait(5000);
            taskCompletionSource3.Task.Wait(5000);

            var result1 = taskCompletionSource1.Task.Result;

            Assert.IsNotNull(result1);
            Assert.IsNotNull(result1.Data.GetByteStream().GetContentAsByteArray());
            var result2 = taskCompletionSource1.Task.Result;

            Assert.IsNotNull(result2);
            Assert.IsNotNull(result2.Data.GetByteStream().GetContentAsByteArray());
            var result3 = taskCompletionSource1.Task.Result;

            Assert.IsNotNull(result3);
            Assert.IsNotNull(result3.Data.GetByteStream().GetContentAsByteArray());
        }
Esempio n. 30
0
        /// <summary>
        /// 下载视频
        /// </summary>
        /// <returns></returns>
        public override bool Download()
        {
            //开始下载
            delegates.TipText(new ParaTipText(this.Info, "正在分析视频地址"));

            //修正井号
            Info.Url = Info.Url.TrimEnd('#');

            //修正简写URL
            if (Regex.Match(Info.Url, @"^ac\d+$").Success)
            {
                Info.Url = "http://www.acfun.tv/v/" + Info.Url;
            }
            else if (!Info.Url.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))
            {
                Info.Url = "http://" + Info.Url;
            }

            //修正URL为 http://www.acfun.tv/v/ac12345_67 形式
            Info.Url = Info.Url.Replace(".html", "").Replace("/index", "");
            if (!Info.Url.Contains("_"))
            {
                Info.Url += "_1";
            }

            //取得AC号和子编号
            Match mAcNumber = Regex.Match(Info.Url, @"(?<ac>ac\d+)_(?<sub>\d+)");

            m_acNumber    = mAcNumber.Groups["ac"].Value;
            m_acSubNumber = mAcNumber.Groups["sub"].Value;
            //设置自定义文件名
            m_customFileName = AcFunPlugin.DefaultFileNameFormat;
            if (Info.BasePlugin.Configuration.ContainsKey("CustomFileName"))
            {
                m_customFileName = Info.BasePlugin.Configuration["CustomFileName"];
            }

            //是否通过【自动应答】禁用对话框
            bool disableDialog = false;

            disableDialog = AutoAnswer.IsInAutoAnswers(Info.AutoAnswer, "acfun", "auto");

            //当前播放器地址
            Settings["PlayerUrl"] = @"http://static.acfun.tv/player/ssl/ACFlashPlayerN0102.swf";

            //取得网页源文件
            string src = Network.GetHtmlSource(Info.Url, Encoding.UTF8, Info.Proxy);

            var relatedVideoList = new Dictionary <string, string>();


            TipText("正在获取视频详细信息");
            var videoIdCollection = Regex.Matches(src,
                                                  @"<a data-vid=""(?<vid>\d+)"" data-from=""(?<from>\w+)""(?: data-did=""(?<did>\w*?)"")? data-sid=""(?<sid>\w+)"" href=""(?<href>.+?)"" title=""(?<title>.+?)"".+?>(?<content>.+?)</a>",
                                                  RegexOptions.IgnoreCase);

            foreach (Match mVideoId in videoIdCollection)
            {
                //所有子标题
                if (mVideoId.Groups["content"].Value.Contains("<i"))                 //当前标题
                {
                    m_currentPartTitle   = Regex.Replace(mVideoId.Groups["content"].Value, @"<i.+?i>", "", RegexOptions.IgnoreCase);
                    m_currentPartVideoId = mVideoId.Groups["vid"].Value;
                }
                else                 //其他标题
                {
                    relatedVideoList.Add("http://www.acfun.tv" + mVideoId.Groups["href"].Value, mVideoId.Groups["content"].Value);
                }
            }


            //取得视频标题
            var videoTitleMatchResult = Regex.Match(src, @"(?<=system\.title = \$\.parseSafe\(')(.+?)(?='\))", RegexOptions.IgnoreCase);

            if (!videoTitleMatchResult.Success)
            {
                videoTitleMatchResult = Regex.Match(src, @"(?<=<title>).+?(?=</title>)", RegexOptions.IgnoreCase);
            }
            m_videoTitle       = videoTitleMatchResult.Value;
            m_currentPartTitle = string.IsNullOrEmpty(m_currentPartTitle) ? m_videoTitle : m_currentPartTitle;
            m_currentPartTitle = m_currentPartTitle.Replace(" - AcFun弹幕视频网 - 中国宅文化基地", "");

            //取得当前视频完整标题
            Info.Title         = m_videoTitle + " - " + m_currentPartTitle;
            m_videoTitle       = Tools.InvalidCharacterFilter(m_videoTitle, "");
            m_currentPartTitle = Tools.InvalidCharacterFilter(m_currentPartTitle, "");

            //解析关联项需要同时满足的条件:
            //1.这个任务不是被其他任务所添加的
            //2.用户设置了“解析关联项”
            TipText("正在选择关联视频");
            if (!Info.IsBeAdded && Info.ParseRelated && relatedVideoList.Count > 0)
            {
                //用户选择任务
                var ba = new Collection <string>();
                if (!disableDialog)
                {
                    ba = ToolForm.CreateMultiSelectForm(relatedVideoList, Info.AutoAnswer, "acfun");
                }
                //根据用户选择新建任务
                foreach (string u in ba)
                {
                    //新建任务
                    delegates.NewTask(new ParaNewTask(Info.BasePlugin, u, this.Info));
                }
            }


            //视频地址数组
            //清空地址
            Info.FilePath.Clear();
            Info.SubFilePath.Clear();

            //下载弹幕
            DownloadSubtitle(m_currentPartVideoId);

            TipText("正在解析视频源地址");
            //解析器的解析结果
            ParseResult pr = null;

            //如果允许下载视频
            if ((Info.DownloadTypes & DownloadType.Video) != 0)
            {
                var parser = new AcfunInterfaceParser();
                pr = parser.Parse(new ParseRequest
                {
                    Id          = m_currentPartVideoId,
                    Proxy       = Info.Proxy,
                    AutoAnswers = Info.AutoAnswer
                });

                //视频地址列表
                var videos = pr.ToArray();
                //支持导出列表
                if (videos != null)
                {
                    var sb = new StringBuilder();
                    foreach (string item in videos)
                    {
                        sb.Append(item);
                        sb.Append("|");
                    }
                    Settings["ExportUrl"] = sb.ToString();
                }

                //下载视频
                TipText("正在开始下载视频文件");
                //确定视频共有几个段落
                Info.PartCount = videos.Length;

                //------------分段落下载------------
                for (int i = 0; i < Info.PartCount; i++)
                {
                    Info.CurrentPart = i + 1;

                    //取得文件后缀名
                    string ext = Tools.GetExtension(videos[i]);
                    if (string.IsNullOrEmpty(ext))
                    {
                        if (string.IsNullOrEmpty(Path.GetExtension(videos[i])))
                        {
                            ext = ".flv";
                        }
                        else
                        {
                            ext = Path.GetExtension(videos[i]);
                        }
                    }
                    if (ext == ".hlv")
                    {
                        ext = ".flv";
                    }

                    //设置文件名
                    var    renamehelper = new CustomFileNameHelper();
                    string filename     = renamehelper.CombineFileName(m_customFileName,
                                                                       m_videoTitle, m_currentPartTitle, Info.PartCount == 1 ? "" : Info.CurrentPart.ToString(),
                                                                       ext.Replace(".", ""), m_acNumber, m_acSubNumber);
                    filename = Path.Combine(Info.SaveDirectory.ToString(), filename);

                    //添加文件名到文件列表中
                    Info.FilePath.Add(filename);

                    //生成父文件夹
                    if (!Directory.Exists(Path.GetDirectoryName(filename)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(filename));
                    }

                    //设置当前DownloadParameter
                    currentParameter = new DownloadParameter()
                    {
                        //文件名
                        FilePath = filename,
                        //文件URL
                        Url = videos[i],
                        //代理服务器
                        Proxy = Info.Proxy,
                        //提取缓存
                        ExtractCache        = Info.ExtractCache,
                        ExtractCachePattern = "fla*.tmp"
                    };

                    //下载文件
                    bool success = false;

                    //提示更换新Part
                    delegates.NewPart(new ParaNewPart(this.Info, i + 1));

                    //下载视频
                    try
                    {
                        success = Network.DownloadFile(currentParameter, this.Info);
                        if (!success)                         //未出现错误即用户手动停止
                        {
                            return(false);
                        }
                    }
                    catch                     //下载文件时出现错误
                    {
                        //如果此任务由一个视频组成,则报错(下载失败)
                        if (Info.PartCount == 1)
                        {
                            throw;
                        }
                        else                         //否则继续下载,设置“部分失败”状态
                        {
                            Info.PartialFinished        = true;
                            Info.PartialFinishedDetail += "\r\n文件: " + currentParameter.Url + " 下载失败";
                        }
                    }
                }         //end for
            }             //end 判断是否下载视频


            //如果插件设置中没有GenerateAcPlay项,或此项设置为true则生成.acplay快捷方式
            if (!Info.BasePlugin.Configuration.ContainsKey("GenerateAcPlay") ||
                Info.BasePlugin.Configuration["GenerateAcPlay"] == "true")
            {
                //生成AcPlay文件
                string acplay = GenerateAcplayConfig(pr);
                //支持AcPlay直接播放
                Settings["AcPlay"] = acplay;
            }

            //生成视频自动合并参数
            if (Info.FilePath.Count > 1 && !Info.PartialFinished)
            {
                Info.Settings.Remove("VideoCombine");
                var arg = new StringBuilder();
                foreach (var item in Info.FilePath)
                {
                    arg.Append(item);
                    arg.Append("|");
                }

                var    renamehelper = new CustomFileNameHelper();
                string filename     = renamehelper.CombineFileName(m_customFileName,
                                                                   m_videoTitle, m_currentPartTitle, "",
                                                                   "mp4", m_acNumber, m_acSubNumber);
                filename = Path.Combine(Info.SaveDirectory.ToString(), filename);

                arg.Append(filename);
                Info.Settings["VideoCombine"] = arg.ToString();
            }

            //下载成功完成
            return(true);
        }
Esempio n. 31
0
        /// <summary>
        /// 下载视频
        /// </summary>
        /// <returns></returns>
        public override bool Download()
        {
            //开始下载
            delegates.TipText(new ParaTipText(this.Info, "正在分析视频地址"));

            //修正井号
            Info.Url = Info.Url.TrimEnd('#');
            //修正简写URL
            if (Regex.Match(Info.Url, @"^ac\d+$").Success)
            {
                Info.Url = "http://www.acfun.tv/v/" + Info.Url;
            }

            //修正index.html
            if (!Info.Url.EndsWith(".html"))
            {
                if (Info.Url.EndsWith("/"))
                {
                    Info.Url += "index.html";
                }
                else
                {
                    Info.Url += "/index.html";
                }
            }

            string url = Info.Url;
            //取得子页面文件名(例如"index_123.html")
            string suburl = Regex.Match(Info.Url, @"ac\d+/(?<part>index\.html|index_\d+\.html)").Groups["part"].Value;

            //取得AC号和子编号
            Match mACNumber = Regex.Match(Info.Url, @"(?<ac>ac\d+)/index(_(?<sub>\d+)|)\.html");

            Settings["ACNumber"]    = mACNumber.Groups["ac"].Value;
            Settings["ACSubNumber"] = mACNumber.Groups["sub"].Success ? mACNumber.Groups["sub"].Value : "1";
            //设置自定义文件名
            Settings["CustomFileName"] = AcFunPlugin.DefaultFileNameFormat;
            if (Info.BasePlugin.Configuration.ContainsKey("CustomFileName"))
            {
                Settings["CustomFileName"] = Info.BasePlugin.Configuration["CustomFileName"];
            }

            //是否通过【自动应答】禁用对话框
            bool disableDialog = false;

            if (Info.AutoAnswer != null)
            {
                foreach (var item in Info.AutoAnswer)
                {
                    if (item.Prefix == "acfun")
                    {
                        if (item.Identify == "auto")
                        {
                            disableDialog = true;
                        }
                        break;
                    }
                }
            }

            try
            {
                //取得网页源文件
                string src = Network.GetHtmlSource(url, Encoding.UTF8, Info.Proxy);

                //分析id和视频存放站点(type)
                string type;
                string id = "";                 //视频id
                //string ot = ""; //视频子id

                //取得embed块的源代码
                Regex  rEmbed   = new Regex(@"\<div id=""area-player""\>.+?\</div\>", RegexOptions.Singleline);
                Match  mEmbed   = rEmbed.Match(src);
                string embedSrc = mEmbed.ToString().Replace("type=\"application/x-shockwave-flash\"", "");

                //检查是否为Flash游戏
                Regex rFlash = new Regex(@"src=""(?<player>.+?)\.swf""");
                Match mFlash = rFlash.Match(embedSrc);

                #region 取得当前Flash播放器地址
                //脚本地址
                string playerScriptUrl = "http:" + Regex.Match(src, @"(?<=<script src="")//static\.acfun\.tv/dotnet/\d+/script/article\.js(?="">)").Value + @"?_version=12289360";
                //脚本源代码
                string playerScriptSrc = Network.GetHtmlSource(playerScriptUrl, Encoding.UTF8, Info.Proxy);
                //swf文件地址
                string playerUrl = Regex.Match(playerScriptSrc, @"http://.+?swf").Value;
                //添加到插件设置中
                if (Info.Settings.ContainsKey("PlayerUrl"))
                {
                    Info.Settings["PlayerUrl"] = playerUrl;
                }
                else
                {
                    Info.Settings.Add("PlayerUrl", playerUrl);
                }

                #endregion


                //如果是Flash游戏
                if (mFlash.Success && !mFlash.Value.Contains("newflvplayer"))
                {
                    type = "game";
                }
                else
                {
                    if (!embedSrc.Contains(@"text/javascript"))                     //旧版本
                    {
                        //获取ID
                        Regex rId = new Regex(@"(\?|amp;|"")id=(?<id>\w+)(?<ot>(-\w*|))");
                        Match mId = rId.Match(embedSrc);
                        id = mId.Groups["id"].Value;
                        if (Info.Settings.ContainsKey("cid"))
                        {
                            Info.Settings["cid"] = id;
                        }
                        else
                        {
                            Info.Settings.Add("cid", id);
                        }


                        //取得type值
                        Regex rType = new Regex(@"type(|\w)=(?<type>\w*)");
                        Match mType = rType.Match(embedSrc);
                        type = mType.Groups["type"].Value;
                        if (type.Equals("video", StringComparison.CurrentCultureIgnoreCase))
                        {
                            type = "sina";
                        }
                    }
                    else
                    {
                        //取得acfun id值
                        Regex  rAcfunId = new Regex(@"'id':'(?<id>\d+)");
                        Match  mAcfunId = rAcfunId.Match(embedSrc);
                        string acfunid  = mAcfunId.Groups["id"].Value;

                        //获取跳转
                        string getvideobyid = Network.GetHtmlSource("http://www.acfun.tv/api/getVideoByID.aspx?vid=" + acfunid, Encoding.UTF8);

                        //将信息添加到Setting中
                        Regex           rVideoInfo  = new Regex(@"""(?<key>.+?)"":(""|)(?<value>.+?)(""|)[,|}]");
                        MatchCollection mcVideoInfo = rVideoInfo.Matches(getvideobyid);
                        foreach (Match mVideoInfo in mcVideoInfo)
                        {
                            string key   = mVideoInfo.Groups["key"].Value;
                            string value = mVideoInfo.Groups["value"].Value;
                            if (Info.Settings.ContainsKey(key))
                            {
                                Info.Settings[key] = value;
                            }
                            else
                            {
                                Info.Settings.Add(key, value);
                            }
                        }

                        id   = Info.Settings["vid"];
                        type = Info.Settings["vtype"];
                    }
                }

                //取得视频标题
                Regex  rTitle = new Regex(@"<title>(?<title>.*)</title>");
                Match  mTitle = rTitle.Match(src);
                string title  = mTitle.Groups["title"].Value.Replace(" - Acfun", "").Replace(" - 天下漫友是一家", "");

                //取得所有子标题
                Regex           rSubTitle  = new Regex(@"<a class=""pager pager-article"" href=""(?<part>.+?)"">(?<content>.+?)</a>");
                MatchCollection mSubTitles = rSubTitle.Matches(src);


                //如果存在下拉列表框
                if (mSubTitles.Count > 0)
                {
                    //解析关联项需要同时满足的条件:
                    //1.这个任务不是被其他任务所添加的
                    //2.用户设置了“解析关联项”
                    if (!Info.IsBeAdded)
                    {
                        if (Info.ParseRelated)
                        {
                            //准备(地址-标题)字典
                            var dict = new Dictionary <string, string>();
                            foreach (Match item in mSubTitles)
                            {
                                dict.Add(url.Replace(suburl, item.Groups["part"].Value),
                                         item.Groups["content"].Value);
                            }
                            //用户选择任务
                            var ba = new Collection <string>();
                            if (!disableDialog)
                            {
                                ba = ToolForm.CreateMultiSelectForm(dict, Info.AutoAnswer, "acfun");
                            }
                            //根据用户选择新建任务
                            foreach (string u in ba)
                            {
                                //新建任务
                                delegates.NewTask(new ParaNewTask(Info.BasePlugin, u, this.Info));
                            }
                        }
                    }
                }


                Info.Title = title;
                //过滤非法字符
                title = Tools.InvalidCharacterFilter(title, "");

                //视频地址数组
                string[] videos = null;
                //清空地址
                Info.FilePath.Clear();
                Info.SubFilePath.Clear();


                //下载弹幕
                bool comment = DownloadSubtitle(title);
                if (!comment)
                {
                    Info.PartialFinished        = true;
                    Info.PartialFinishedDetail += "\r\n弹幕文件文件下载失败";
                }

                //解析器的解析结果
                ParseResult pr = null;

                //如果允许下载视频
                if ((Info.DownloadTypes & DownloadType.Video) != 0)
                {
                    //检查type值
                    switch (type)
                    {
                    case "sina":                             //新浪视频
                        //解析视频
                        SinaVideoParser parserSina = new SinaVideoParser();
                        pr = parserSina.Parse(new ParseRequest()
                        {
                            Id = id, Proxy = Info.Proxy, AutoAnswers = Info.AutoAnswer
                        });
                        videos = pr.ToArray();
                        break;

                    case "qq":                             //QQ视频
                        //解析视频
                        QQVideoParser parserQQ = new QQVideoParser();
                        pr = parserQQ.Parse(new ParseRequest()
                        {
                            Id = id, Proxy = Info.Proxy, AutoAnswers = Info.AutoAnswer
                        });
                        videos = pr.ToArray();
                        break;

                    case "youku":                             //优酷视频
                        //解析视频
                        YoukuParser parserYouKu = new YoukuParser();
                        pr = parserYouKu.Parse(new ParseRequest()
                        {
                            Id = id, Proxy = Info.Proxy, AutoAnswers = Info.AutoAnswer
                        });
                        videos = pr.ToArray();
                        break;

                    case "tudou":                             //土豆视频
                        TudouParser parserTudou = new TudouParser();
                        pr = parserTudou.Parse(new ParseRequest()
                        {
                            Id = id, Proxy = Info.Proxy, AutoAnswers = Info.AutoAnswer
                        });
                        videos = pr.ToArray();
                        break;

                    case "game":                             //flash游戏
                        videos = new string[] { mFlash.Groups["player"].Value };
                        break;
                    }

                    Info.videos = videos;
                    return(true);

                    //下载视频
                    //确定视频共有几个段落
                    Info.PartCount = videos.Length;

                    //------------分段落下载------------
                    for (int i = 0; i < Info.PartCount; i++)
                    {
                        Info.CurrentPart = i + 1;

                        //取得文件后缀名
                        string ext = Tools.GetExtension(videos[i]);
                        if (string.IsNullOrEmpty(ext))
                        {
                            if (string.IsNullOrEmpty(Path.GetExtension(videos[i])))
                            {
                                ext = ".flv";
                            }
                            else
                            {
                                ext = Path.GetExtension(videos[i]);
                            }
                        }
                        if (ext == ".hlv")
                        {
                            ext = ".flv";
                        }

                        //设置文件名
                        var    renamehelper = new CustomFileNameHelper();
                        string filename     = renamehelper.CombineFileName(Settings["CustomFileName"],
                                                                           title, "", Info.PartCount == 1 ? "" : Info.CurrentPart.ToString(),
                                                                           ext.Replace(".", ""), Info.Settings["ACNumber"], Info.Settings["ACSubNumber"]);
                        filename = Path.Combine(Info.SaveDirectory.ToString(), filename);

                        //生成父文件夹
                        if (!Directory.Exists(Path.GetDirectoryName(filename)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        }

                        //设置当前DownloadParameter
                        currentParameter = new DownloadParameter()
                        {
                            //文件名
                            FilePath = filename,
                            //文件URL
                            Url = videos[i],
                            //代理服务器
                            Proxy = Info.Proxy,
                            //提取缓存
                            ExtractCache        = Info.ExtractCache,
                            ExtractCachePattern = "fla*.tmp"
                        };


                        //设置代理服务器
                        currentParameter.Proxy = Info.Proxy;
                        //添加文件路径到List<>中
                        Info.FilePath.Add(currentParameter.FilePath);
                        //下载文件
                        bool success = false;

                        //提示更换新Part
                        delegates.NewPart(new ParaNewPart(this.Info, i + 1));

                        //下载视频
                        try
                        {
                            success = Network.DownloadFile(currentParameter, this.Info);
                            if (!success)                             //未出现错误即用户手动停止
                            {
                                return(false);
                            }
                        }
                        catch (Exception ex)                         //下载文件时出现错误
                        {
                            //如果此任务由一个视频组成,则报错(下载失败)
                            if (Info.PartCount == 1)
                            {
                                throw ex;
                            }
                            else                             //否则继续下载,设置“部分失败”状态
                            {
                                Info.PartialFinished        = true;
                                Info.PartialFinishedDetail += "\r\n文件: " + currentParameter.Url + " 下载失败";
                            }
                        }
                    }            //end for
                }                //end 判断是否下载视频


                //如果插件设置中没有GenerateAcPlay项,或此项设置为true则生成.acplay快捷方式
                if (!Info.BasePlugin.Configuration.ContainsKey("GenerateAcPlay") ||
                    Info.BasePlugin.Configuration["GenerateAcPlay"] == "true")
                {
                    //生成AcPlay文件
                    string acplay = GenerateAcplayConfig(pr, title);
                    //支持AcPlay直接播放
                    Info.Settings["AcPlay"] = acplay;
                }

                //支持导出列表
                if (videos != null)
                {
                    StringBuilder sb = new StringBuilder(videos.Length * 2);
                    foreach (string item in videos)
                    {
                        sb.Append(item);
                        sb.Append("|");
                    }
                    if (Info.Settings.ContainsKey("ExportUrl"))
                    {
                        Info.Settings["ExportUrl"] = sb.ToString();
                    }
                    else
                    {
                        Info.Settings.Add("ExportUrl", sb.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //下载成功完成
            return(true);
        }
Esempio n. 32
0
        public override bool Download()
        {
            //开始下载
            TipText("正在开始任务");

            //获取视频编号
            string sm = Regex.Match(Info.Url, @"(?<=(http://www\.nicovideo\.jp/watch/|))sm\d+").Value;

            //修正简写URL
            if (Info.Url.StartsWith("sm", StringComparison.CurrentCultureIgnoreCase))
            {
                Info.Url = "http://www.nicovideo.jp/watch/" + Info.Url;
            }

            //获取网页源代码
            string src = Network.GetHtmlSource(Info.Url, Encoding.UTF8, Info.Proxy);
            //匹配登录按钮
            Match mLoginButton = Regex.Match(src, "(?<=アカウント新規登録へ.+?<a href=\").+?(?=\">.+?ログイン画面へ)");
            //获取登录地址
            string loginUrl = mLoginButton.Value;

            TipText("正在登录Nico");

            //向网页Post数据
            CookieContainer cookies = new CookieContainer();
            //登录NicoNico
            UserLoginInfo user;

            //检查插件配置
            try
            {
                user          = new UserLoginInfo();
                user.Username = Encoding.UTF8.GetString(Convert.FromBase64String(Info.Settings["user"]));
                user.Password = Encoding.UTF8.GetString(Convert.FromBase64String(Info.Settings["password"]));
                if (string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password))
                {
                    throw new Exception();
                }
            }
            catch
            {
                user = ToolForm.CreateLoginForm(null, "https://secure.nicovideo.jp/secure/register");
                Info.Settings["user"]     = Convert.ToBase64String(Encoding.UTF8.GetBytes(user.Username));
                Info.Settings["password"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(user.Password));
            }
            //Post的数据
            string postdata = string.Format("next_url={0}&mail={1}&password={2}", sm, Tools.UrlEncode(user.Username), Tools.UrlEncode(user.Password));

            byte[] data = Encoding.UTF8.GetBytes(postdata);
            //生成请求
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://secure.nicovideo.jp/secure/login?site=niconico");

            req.Proxy             = Info.Proxy;
            req.AllowAutoRedirect = false;
            req.Method            = "POST";
            req.Referer           = loginUrl;
            req.ContentType       = "application/x-www-form-urlencoded";
            req.ContentLength     = data.Length;
            req.UserAgent         = "Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0";
            req.CookieContainer   = new CookieContainer();
            //发送POST数据
            using (var outstream = req.GetRequestStream())
            {
                outstream.Write(data, 0, data.Length);
                outstream.Flush();
            }
            //关闭请求
            req.GetResponse().Close();
            cookies = req.CookieContainer;             //保存cookies

            TipText("正在解析视频标题");

            //解析视频标题
            HttpWebRequest reqTitle = (HttpWebRequest)HttpWebRequest.Create(Info.Url);

            reqTitle.Proxy = Info.Proxy;
            //设置cookies
            reqTitle.CookieContainer = cookies;
            //获取视频信息
            string srcTitle = Network.GetHtmlSource(reqTitle, Encoding.UTF8);

            //视频标题
            Info.Title = Regex.Match(srcTitle, @"(?<=<title>).+?(?=</title>)").Value.Replace("‐ ニコニコ動画(原宿)", "").Trim();
            //Info.Title = Regex.Match(srcTitle, @"(?<=<span class=""videoHeaderTitle"">).+?(?=</span>)").Value;
            string title = Tools.InvalidCharacterFilter(Info.Title, "");

            TipText("正在分析视频地址");

            //通过API获取视频信息
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"http://flapi.nicovideo.jp/api/getflv/" + sm);

            request.Method = "POST";
            request.Proxy  = Info.Proxy;
            //设置cookies
            request.CookieContainer = cookies;
            //获取视频信息
            string videoinfo = Network.GetHtmlSource(request, Encoding.ASCII);
            //视频真实地址
            string video = Regex.Match(videoinfo, @"(?<=url=).+?(?=&)").Value;

            video = video.Replace("%3A", ":").Replace("%2F", "/").Replace("%3F", "?").Replace("%3D", "=");

            //下载视频
            NewPart(1, 1);

            //设置下载参数
            currentParameter = new DownloadParameter()
            {
                //文件名 例: c:\123(1).flv
                FilePath = Path.Combine(Info.SaveDirectory.ToString(),
                                        title + ".mp4"),
                //文件URL
                Url = video,
                //代理服务器
                Proxy = Info.Proxy,
                //Cookie
                Cookies = cookies,
                //提取缓存
                ExtractCache        = Info.ExtractCache,
                ExtractCachePattern = "fla*.tmp"
            };

            //下载视频
            bool success = Network.DownloadFile(currentParameter, this.Info);

            if (!success)             //未出现错误即用户手动停止
            {
                return(false);
            }

            return(true);
        }
        private void downloadOneFile(int fileIndex)
        {
            // check if we reach the end of the list
            if (fileIndex < this.DownloadListView.Items.Count)
            {
                // check if we need to download the file or if we need to skip it
                ListViewItem item = this.DownloadListView.Items[fileIndex];
                if (item.Checked)
                {
                    // get the URL and destination and create a parameter for async work
                    ListViewItem.ListViewSubItemCollection subitems = item.SubItems;
                    DownloadParameter parameters = new DownloadParameter();
                    parameters.url = subitems[SUBITEM_URL_INDEX].Text;
                    parameters.destination = System.Windows.Forms.Application.StartupPath + subitems[SUBITEM_DEST_INDEX].Text;
                    parameters.fileIndex = fileIndex;

                    // start the download asynchronously by giving the parameters
                    downloadBackgroundWorker.RunWorkerAsync(parameters);
                    // this method will be called again when the background worker will send it complete event
                }
                else
                {
                    // clear the download area
                    item.SubItems[SUBITEM_PERCENTAGE_INDEX].Text = string.Empty;
                    // if we need to skip this file, download the next one
                    updatePercentageOfTotalBar(fileIndex, 100);
                    downloadOneFile(fileIndex + 1);
                }
            }
            else
            {
                // if we reach the end of the list, the download is complete
                downloadComplete();
            }
        }
Esempio n. 34
0
 internal FilePartData(DownloadParameter downloadParameter, byte[] data)
 {
     DownloadParameter = downloadParameter;
     FileBytes = data;
 }