예제 #1
0
 public m3u8Download(m3u8File m, int id, bool automerge, m3u8DownloadCallBack cb)
 {
     m3u8           = m;
     callBack       = cb;
     status         = 0;
     this.id        = id;
     this.automerge = automerge;
 }
예제 #2
0
        public void OnDownloadAllDataReceived(Aria2Download.Status status, int id, string str)
        {
            dt.Rows[id][4] = str;
            if (status == Aria2Download.Status.Failed || status == Aria2Download.Status.Finished)
            {//处理完成一个(包括下载成功或失败),处理下一个
                finishList[id] = status;

                for (id = id + 1; id < dt.Rows.Count; id++)
                {
                    if (finishList[id] == Aria2Download.Status.NoStart)
                    {//未下载
                        m3u8Download download = new m3u8Download((m3u8File)(dt.Rows[id][5]), id, chkMerge.Checked, DownloadAllDataReceived);
                        download.start();
                        finishList[id] = Aria2Download.Status.Running;
                        break;
                    }
                }

                if (id >= dt.Rows.Count)
                {
                    for (int i = 0; i < finishList.Count; i++)
                    {
                        if (finishList[i] == Aria2Download.Status.Running)
                        {
                            falseList.Clear();
                            successList.Clear();
                            return;//等待其他下载完毕
                        }
                        else if (finishList[i] == Aria2Download.Status.Failed)
                        {
                            falseList.Add(i);
                        }
                        else if (finishList[i] == Aria2Download.Status.Finished)
                        {
                            successList.Add(i);
                        }
                    }
                    MessageBox.Show("成功:" + successList.Count + ",失败" + falseList.Count + "个", "下载完成");
                }
            }
        }
예제 #3
0
        public void OnDataReceived(Aria2Download.Status status, int progress)
        {
            //            dt.Rows[0][4] = "当前进度: " + progress + "%";

            this.status = status;
            switch (status)
            {
            case Aria2Download.Status.Finished:
                //下载完成
                downloadNo++;
                if (downloadNo < m3u8.DownloadUrl.Count)
                {    //下载下一个
                    if (callBack != null)
                    {
                        callBack(Aria2Download.Status.Running, id, "下载:" + (downloadNo - 1).ToString() + "/" + m3u8.DownloadUrl.Count + "  " + progress + "%");
                    }
                    start();
                }
                else if (downloadNo == m3u8.DownloadUrl.Count)
                {
                    if (m3u8.keyPath.StartsWith("http"))
                    {
                        Aria2DownloadCallBack cb         = new Aria2DownloadCallBack(OnDataReceived);
                        Aria2Download         mydownload = new Aria2Download(m3u8.keyPath, "Downloads\\" + m3u8.name + "\\key.key", cb);
                        mydownload.Start();
                        Console.WriteLine(m3u8.name + ":开始下载key");
                    }
                    else
                    {
                        try
                        {
                            File.Copy(m3u8.keyPath, m3u8.name + "\\key.key", true);

                            if (automerge)
                            {
                                this.status = Aria2Download.Status.Running;
                                if (callBack != null)
                                {
                                    callBack(status, id, "下载完成  " + m3u8.DownloadUrl.Count + "/" + m3u8.DownloadUrl.Count);
                                }
                                m3u8Merge();
                            }
                            else
                            {
                                this.status = Aria2Download.Status.Finished;
                                if (callBack != null)
                                {
                                    callBack(status, id, "下载完成  " + m3u8.DownloadUrl.Count + "/" + m3u8.DownloadUrl.Count);
                                }
                            }
                        }
                        catch
                        {
                            this.status = Aria2Download.Status.Failed;
                            if (callBack != null)
                            {
                                callBack(status, id, "下载Key失败  " + m3u8.DownloadUrl.Count + "/" + m3u8.DownloadUrl.Count);
                            }
                        }
                    }
                }
                else if (downloadNo > m3u8.DownloadUrl.Count)
                {
                    if (automerge)
                    {
                        this.status = Aria2Download.Status.Running;
                        if (callBack != null)
                        {
                            callBack(status, id, "下载完成  " + m3u8.DownloadUrl.Count + "/" + m3u8.DownloadUrl.Count);
                        }
                        m3u8Merge();
                    }
                    else
                    {
                        this.status = Aria2Download.Status.Finished;
                        if (callBack != null)
                        {
                            callBack(status, id, "下载完成  " + m3u8.DownloadUrl.Count + "/" + m3u8.DownloadUrl.Count);
                        }
                    }
                }
                break;

            case Aria2Download.Status.Running:
                if (callBack != null)
                {
                    callBack(status, id, "下载:" + downloadNo + "/" + m3u8.DownloadUrl.Count + "  " + progress + "%");
                }
                break;

            case Aria2Download.Status.Failed:
                if (callBack != null)
                {
                    callBack(status, id, "失败!" + downloadNo + "/" + m3u8.DownloadUrl.Count);
                }
                break;

            case Aria2Download.Status.Paused:
                if (callBack != null)
                {
                    callBack(status, id, "下载暂停 " + downloadNo + "/" + m3u8.DownloadUrl.Count + "  " + progress + "%");
                }
                break;
            }

            Console.WriteLine("当前进度: " + progress + "%");
        }
예제 #4
0
 public void OnSelectDownloadDataReceived(Aria2Download.Status status, int id, string str)
 {
     dt.Rows[id][4] = str;
 }