public static CQCode GetIllustPic(Pixiv_PID info) { string path = Path.Combine(Environment.CurrentDirectory, "data", "image", "LoliconPic", $"{info.data.id}.jpg"); string pathcqcode = Path.Combine("LoliConPic", $"{info.data.id}.jpg"); using (HttpWebClient http = new HttpWebClient()) { http.TimeOut = 5000; try { if (!File.Exists(path)) { string url = string.Empty; url = info.data.imageUrls[0].original.Replace("pximg.net", "pixiv.cat"); http.DownloadFile(url, path); CommonHelper.AntiHX(path); MainSave.CQLog.Info("插画详情", "图片下载成功,正在尝试发送"); } } catch (Exception e) { MainSave.CQLog.Info("插画详情", $"图片下载失败,错误信息:{e.Message}"); return(CQApi.CQCode_Image("Error.jpg")); } } return(CQApi.CQCode_Image(pathcqcode)); }
public static string GetIllustReturnText(Pixiv_PID info) { string text = $"标题:{info.data.title}\n" + $"作者:{info.data.artistPreView.name}\n" + $"pid={info.data.id}\n" + $"创作日期:{info.data.createDate}\n" + $"浏览数:{info.data.totalView}\n" + $"收藏数:{info.data.totalBookmarks}"; MainSave.CQLog.Info("插画详情", "详情获取成功,正在拉取图片"); return(text); }
/// <summary> /// 获取图片详情及原图 /// </summary> /// <param name="id">图片的Pid</param> /// <returns></returns> public static IllustInfo GetIllustInfo(int id) { using (HttpWebClient http = new HttpWebClient() { TimeOut = 10000, Encoding = Encoding.UTF8, Proxy = MainSave.Proxy, AllowAutoRedirect = true, }) { string url = $"https://pix.ipv4.host/illusts/{id}"; string returnstr = string.Empty; try { string authCode = PublicVariables.PixivicAuth; if (string.IsNullOrEmpty(authCode)) { MainSave.CQLog.Info("未填写授权码", "搜图需要在数据目录的Config.ini文件内,Config字段的PixivicAuth值内填入获取到的授权码"); throw new Exception(); } http.Encoding = Encoding.UTF8; http.Headers.Add("authorization", authCode); returnstr = http.DownloadString(url); Pixiv_PID infobase = JsonConvert.DeserializeObject <Pixiv_PID>(returnstr); bool r18_Flag = infobase.data.tags.Any(x => x.name.Contains("R-18")); if (r18_Flag && !PublicVariables.R18_Flag) { IllustInfo R18Pic = new IllustInfo() { IllustText = "设置内限制级图片,不予显示", IllustCQCode = new CQCode(CQFunction.Image, new KeyValuePair <string, string>("file", "Error.jpg")) }; return(R18Pic); } IllustInfo illustInfo = new IllustInfo() { IllustText = Pixiv_Illust.GetIllustReturnText(infobase), IllustCQCode = Pixiv_Illust.GetIllustPic(infobase), R18_Flag = r18_Flag }; illustInfo.IllustUrl = infobase.data.imageUrls[0].original.Replace("pximg.net", "pixiv.cat"); return(illustInfo); } catch (Exception e) { if (!Directory.Exists(MainSave.AppDirectory + "error\\" + "IllustInfo\\")) { Directory.CreateDirectory(MainSave.AppDirectory + "error\\" + "IllustInfo\\"); } IniConfig ini = new IniConfig(MainSave.AppDirectory + "error\\" + "IllustInfo\\" + $"{DateTime.Now:yyyyMMddHHss}.log"); ini.Object["Error"]["Message"] = e.Message; ini.Object["Error"]["StackTrace"] = e.StackTrace; ini.Object["Error"]["Object"] = returnstr; ini.Save(); MainSave.CQLog.Info("图片详情", $"解析失败,错误信息:{e.Message}"); IllustInfo illustInfo = new IllustInfo() { IllustText = "图片解析失败,作品不存在或被删除", IllustCQCode = CQApi.CQCode_Image("Error.jpg") }; return(illustInfo); } } }