示例#1
0
        /// <summary>
        /// 获取指定作品的动画
        /// </summary>
        protected void GetCanvasZipFile(string itemUrl, string savePath, string pid)
        {
            //可以获取zip的url
            var zipHtmlUrl = string.Format("https://www.pixiv.net/ajax/illust/{0}/ugoira_meta", pid);

            var html = DownHelp.GetHtmlString(zipHtmlUrl, Encoding.UTF8, 5);
            var fReg = new Regex(RegexHelp.Other.GetAnimation, RegexOptions.Singleline);
            var fM   = fReg.Match(html);

            if (fM == null || fM.Groups["Url"].Value == "")
            {
                AddErrorMsg(string.Format("获取 {0} 的动画失败!\r\n", itemUrl));
                return;
            }

            //zip的Url路径
            var fileUrl = fM.Groups["Url"].Value.Replace("\\/", "/");

            //zip文件名
            var fileName = savePath + "/" + Path.GetFileName(fileUrl);

            lock (Multithreading.ObjLockExistFile)
            {
                if (File.Exists(fileName))
                {
                    if (MyForm.ChkNeglect.Checked)
                    {
                        AddErrorMsg(string.Format("文件{0}已存在,已忽略!\r\n", fileName));
                    }
                    return;
                }
            }

            //获取文件总大小
            var total = HtmlHelp.GetFileContenLength(fileUrl, itemUrl);

            if (total == 0)
            {
                AddErrorMsg(string.Format("获取 {0} 的大小失败!\r\n", fileUrl));
                return;
            }

            //分批获取文件
            var b = HtmlHelp.DownFile(fileUrl, fileName, itemUrl, 299999, total);

            if (b)
            {
                AddSuccessMsg(string.Format("下载 {0} 的文件成功!\r\n", fileUrl));
            }
            else
            {
                AddErrorMsg(string.Format("下载 {0} 的文件失败!\r\n Url:{1}\r\n", fileUrl, itemUrl));
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                return;
            }

            //获取delay
            var dr    = new Regex(RegexHelp.Other.GetDelay, RegexOptions.Singleline);
            var dm    = dr.Match(html);
            var delay = "50";

            if (dm != null && dm.Groups["Delay"].Value != "")
            {
                delay = dm.Groups["Delay"].Value;
            }

            var dic = new Dictionary <string, string>()
            {
                { "SavePath", savePath },
                { "FileUrl", fileUrl },
                { "FileName", fileName },
                { "Delay", delay }
            };

            while (!Mut.UnZipFile(dic, UnZipFile))
            {
                Thread.Sleep(5000);
            }
        }