/// <summary> /// parse xml/json list stream and close it. /// </summary> /// <param name="input"></param> /// <param name="option"></param> public DanbooruPostDao(Stream input, DanbooruPostDaoOption option, int?currentPage) { string rawData = ""; this.Option = option; try { using (StreamReader reader = new StreamReader(input)) { rawData = reader.ReadToEnd(); } this.Option = option; switch (option.Provider.Preferred) { case PreferredMethod.Xml: ReadXML(rawData, option); break; case PreferredMethod.Json: ReadJSON(rawData, option); break; case PreferredMethod.Html: DanbooruSearchParam param = new DanbooruSearchParam() { Provider = option.Provider, Tag = option.SearchTags, Page = currentPage, Option = option }; if (option.Provider.BoardType == BoardType.Danbooru) { SankakuComplexParser parser = new SankakuComplexParser(); posts = parser.Parse(rawData, param); NextId = param.NextKey; if (parser.TotalPost.HasValue) { postCount = parser.TotalPost.Value; } } else if (option.Provider.BoardType == BoardType.Gelbooru) { GelbooruHtmlParser parser = new GelbooruHtmlParser(); posts = parser.Parse(rawData, param); } else { throw new NotImplementedException("No HTML Parser for: " + option.Provider.Name); } break; } } catch (Exception) { Helper.DumpRawData(rawData, Option.Provider, option.Query); throw; } }
/// <summary> /// parse xml/json list stream and close it. /// </summary> /// <param name="input"></param> /// <param name="option"></param> public DanbooruPostDao(Stream input, DanbooruPostDaoOption option, int?currentPage) { string rawData = ""; this.Option = option; try { using (StreamReader reader = new StreamReader(input)) { rawData = reader.ReadToEnd(); } this.Option = option; if (rawData.Contains("DDoS protection by <a rel=\"noopener noreferrer\" href=\"https://www.cloudflare.com/5xx-error-landing/\" target=\"_blank\">Cloudflare</a>")) { throw new NotImplementedException($"Cloudflare DDoS protection enabled for : {option.Provider.Name}, please use the cookie method to access."); } switch (option.Provider.Preferred) { case PreferredMethod.Xml: ReadXML(rawData, option); break; case PreferredMethod.Json: ReadJSON(rawData, option); break; case PreferredMethod.Html: DanbooruSearchParam param = new DanbooruSearchParam() { Provider = option.Provider, Tag = option.SearchTags, Page = currentPage, Option = option }; if (option.Provider.BoardType == BoardType.Danbooru) { SankakuComplexParser parser = new SankakuComplexParser(); posts = parser.Parse(rawData, param); NextId = param.NextKey; if (parser.TotalPost.HasValue) { postCount = parser.TotalPost.Value; } } else if (option.Provider.BoardType == BoardType.Gelbooru) { GelbooruHtmlParser parser = new GelbooruHtmlParser(); posts = parser.Parse(rawData, param); } else if (option.Provider.BoardType == BoardType.Shimmie2) { var parser = new ShimmieHtmlParser(); posts = parser.Parse(rawData, param); } else { throw new NotImplementedException("No HTML Parser for: " + option.Provider.Name); } break; } } catch (Exception) { Helper.DumpRawData(rawData, Option.Provider, option.Query); throw; } }