public void download(HuashitongPicture picture, string dirpath) { WebProtocol web; //if (dirpath.LastIndexOf('.') > dirpath.LastIndexOf('\\')) //{ dirpath = new DirectoryInfo(dirpath).Parent.Name; } msg.startProcess(0, picture.imgCount, 1, $"正在下载 {picture.title}({picture.picID})({picture.artist})..."); string url; for (int i = 0; i < picture.imgCount; i++) { try { url = picture.link.Replace("p0.jpg", $"p{i}.jpg").Replace("p0.png", $"p{i}.png"); web = new WebProtocol(url); web.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"; web.Headers.Add("pragma", "no-cache"); web.Headers.Add("sec-fetch-dest", "document"); web.Headers.Add("sec-fetch-mode", "navigate"); web.Headers.Add("sec-fetch-site", "none"); web.Headers.Add("sec-fetch-user", "?1"); var bytes = web.contentBytes; var path = dirpath + $"{picture.generateFilename()}_p{i}.{Path.GetExtension(url)}"; File.WriteAllBytes(path, bytes); msg.stepProcess(); } catch (Exception ex) { msg.puts(); msg.error(ex.Message); } } msg.puts(); // msg.puts($"完成! 共[{picture.imgCount}]张图片"); }
public void downloadByTitle(string title, string dirpath) { pictureList(json(title, 1)); // 为了界面,牺牲一下效率 (约500ms) int jsonCount = this.jsonCount; msg.startProcess(0, jsonCount, 1, "正在分析页面信息..."); HuashitongPicture pic = new HuashitongPicture(title) { title = title }; dirpath += $"{pic.generateFilename()}\\"; for (int index = 1; index <= jsonCount; index++) { var json = this.json(title, index); pictureList(json); msg.stepProcess(); } msg.puts(); msg.success("成功获取页面信息,即将开始下载..."); download(pictureInfo.items, dirpath); }