public void AddBookmark(Illust illust) { string url = "http://www.pixiv.net/bookmark_add.php"; Dictionary<string, string> parms = new Dictionary<string, string>(); parms["mode"] = "add"; parms["type"] = "illust"; parms["restrict"] = "0"; parms["tag"] = ""; parms["comment"] = ""; parms["id"] = illust.IllustID.ToString(); HttpWebRequest req = PostRequest(url, illust.Url, parms); req.GetResponse().Close(); //using(HttpWebResponse res = (HttpWebResponse)req.GetResponse()) //{ //} }
public void GetIllustDetail(ref Illust illust) { Regex reg = null; Match match = null; // イラストページのHtmlを取得する string text = GetHtml(illust.Url); // コメントを取得する if (illust.Comment != string.Empty) { reg = new Regex(ConstData.CommentPattan); match = reg.Match(text); while (match.Success) { illust.Comment = match.Groups["comment"].Value; match = match.NextMatch(); } } // 埋め込みhtmlを取得する if (illust.EmbedHtml != string.Empty) { reg = new Regex(ConstData.EmbedHtmlPattan); match = reg.Match(text); while (match.Success) { illust.EmbedHtml = match.Groups["html"].Value; match = match.NextMatch(); } } // イラストページに記載されているタイトルを取得する string title = ""; reg = new Regex(ConstData.TitlePattan); match = reg.Match(text); while (match.Success) { title = match.Groups["title"].Value; match = match.NextMatch(); } // イラストへの直URLを取得する if ((title != string.Empty) && (illust.ImageUrl == string.Empty || illust.ImageUrl == null)) { title = title.Replace("|", @"\|"); title = title.Replace("+", @"\+"); title = title.Replace("*", @"\*"); title = title.Replace("[", @"\["); title = title.Replace("]", @"\]"); title = title.Replace("(", @"\("); title = title.Replace(")", @"\)"); title = title.Replace("{", @"\("); title = title.Replace("}", @"\)"); title = title.Replace("$", @"\$"); title = title.Replace("^", @"\^"); title = title.Replace(".", @"\."); reg = new Regex(string.Format(ConstData.ImagePattan, title)); match = reg.Match(text); while (match.Success) { illust.ImageUrl = match.Groups["image_url"].Value; match = match.NextMatch(); } } // 作者の名前を取得する if (illust.AuthorName != string.Empty) { reg = new Regex(ConstData.AuthorNamePattan); match = reg.Match(text); while (match.Success) { illust.AuthorName = match.Groups["author"].Value; match = match.NextMatch(); } } // 作者のIDを取得する if (illust.AuthorID != string.Empty) { reg = new Regex(ConstData.PixivIDPattan); match = reg.Match(text); while (match.Success) { illust.AuthorID = match.Groups["id"].Value; illust.AuthorUrl = ConstData.PixivUrl + "/index.php?id=" + match.Groups["id"].Value; match = match.NextMatch(); } } // イラストの数値評価情報を取得する if ((illust.閲覧数 == 0) && (illust.評価数 == 0) && (illust.総合点数 == 0)) { reg = new Regex(ConstData.EtsuranPattan); match = reg.Match(text); while (match.Success) { illust.閲覧数 = long.Parse(match.Groups["eturan"].Value); illust.評価数 = long.Parse(match.Groups["eturan2"].Value); illust.総合点数 = long.Parse(match.Groups["eturan3"].Value); match = match.NextMatch(); } } }
/// <summary> /// Htmlテキストからイラスト情報を取得する /// </summary> /// <param name="text"></param> /// <returns></returns> private List<Illust> GetIllustsFromHtml(PixivPages page, string text) { List<Illust> list = new List<Illust>(); Regex Reg = null; switch (page) { case PixivPages.DailyRanking: case PixivPages.WeeklyRanking: case PixivPages.MonthlyRanking: case PixivPages.R18DailyRanking: case PixivPages.R18WeeklyRanking: case PixivPages.Favorite: case PixivPages.MyPixiv: Reg = new Regex(ConstData.RankingPattan); break; case PixivPages.NewIllust: case PixivPages.R18NewIllust: default: Reg = new Regex(ConstData.NewIllustPattan); break; } // イラスト情報を取得する var matchs = Reg.Match(text); while (matchs.Success) { Illust illust = new Illust(); illust.Url = ConstData.PixivUrl + matchs.Groups["illust_id"].Value; illust.ThumnailImageUrl = matchs.Groups["thumnail"].Value; illust.Title = matchs.Groups["title"].Value; illust.AuthorPixivID = matchs.Groups["author"].Value; illust.ThumnailName = matchs.Groups["thumnailFileName"].Value; // リストにイラスト情報を追加 list.Add(illust); // マッチングした次のイラスト情報 matchs = matchs.NextMatch(); } return list; }
/// <summary> /// イラストを指定したファイルパスにダウンロードする(同期版) /// </summary> /// <param name="illust">イラスト情報</param> /// <param name="filePath">ファイルパス</param> /// <returns></returns> public void DownloadThumnailIllust(Illust illust, string filePath) { DownloadFileAsync(illust.ThumnailImageUrl, filePath); }
/// <summary> /// サムネイルイラストのBitmapデータの取得 /// </summary> /// <param name="illust">イラスト情報</param> /// <returns></returns> public Bitmap GetThumnailBitmap(Illust illust) { Bitmap bmp = null; HttpWebRequest req = GetRequest(illust.ThumnailImageUrl, illust.Url); using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) { bmp = new Bitmap(res.GetResponseStream()); } return bmp; }
/// <summary> /// イラストのBitmapデータの取得 /// </summary> /// <param name="illust">イラスト情報</param> /// <returns>Bitmapオブジェクト</returns> public Bitmap GetBitmap(Illust illust) { Bitmap bmp = null; HttpWebRequest req = GetRequest(illust.ImageUrl, illust.Url); using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) { try { bmp = new Bitmap(res.GetResponseStream()); } catch { bmp = null; } } return bmp; }