public void DoSearch(SynchronizationContext context) { NijieSearchOption option = new NijieSearchOption(); option.Sort = Sort; option.Query = Query; option.Page = Page; option.SearchBy = SearchBy; option.Matching = Matching; try { _search = MainWindow.Bot.Search(option); Images = new ObservableCollection <NijieImageViewModel>(); foreach (var image in _search.Images) { var temp = new NijieImageViewModel(image); context.Send((x) => { Images.Add(temp); }, null); } onPropertyChanged("TotalImages"); } catch (NijieException ne) { Status = "Error: " + ne.Message; } }
/// <summary> /// Parse the search page /// </summary> /// <param name="doc"></param> /// <param name="search"></param> /// <returns></returns> public NijieSearch ParseSearch(HtmlDocument doc, NijieSearch search) { var imagesDiv = doc.DocumentNode.SelectSingleNode("//div[@id='main-left-main']/div[@class='clearfix']").InnerHtml; search.Images = ParseSearchImageList(imagesDiv, search.QueryUrl); //// check next page availability //search.IsNextAvailable = false; //// max image per search page = 48 //// nijie removed the next page button, search based on paging number //var topNav = doc.DocumentNode.SelectNodes("//div[@class='kabu-top']//li"); //if (search.Images.Count == 48 && topNav != null) //{ // int nextPage = search.Option.Page + 1; // foreach (var pageItem in topNav) // { // if (pageItem.InnerText.Contains(nextPage.ToString())) // { // search.IsNextAvailable = true; // break; // } // } //} var imageCountElements = doc.DocumentNode.SelectNodes("//h4/em"); search.TotalImages = ParseTotalImageCount(imageCountElements); // Issue#51 assume the max page based on (total images / 48) + 1 search.IsNextAvailable = ((search.TotalImages / IMAGES_PER_PAGE) + 1 > search.Option.Page); // set next page to false if no images anymore. if (search.Images.Count <= 0) { search.IsNextAvailable = false; } return(search); }
/// <summary> /// Get and parse the search page /// </summary> /// <param name="option"></param> /// <returns></returns> public NijieSearch Search(NijieSearchOption option) { HtmlDocument doc = null; try { canOperate(); if (option.Page < 1) { option.Page = 1; } NijieSearch search = new NijieSearch(option); var result = getPage(search.QueryUrl); if (Util.IsRedirected(result.Item2.ResponseUri.ToString(), search.QueryUrl, true)) { Log.Debug(string.Format("Different Search URL expected: {0} ==> {1}", search.QueryUrl, result.Item2.ResponseUri.ToString())); } doc = result.Item1; return(ParseSearch(doc, search)); } catch (NijieException) { throw; } catch (Exception ex) { if (doc != null) { var filename = string.Format("Dump for Search {0} Page {1}.html", option.Query, option.Page); Log.Debug("Dumping search page to: " + filename); doc.Save(filename); } throw new NijieException(string.Format("Error when processing search: {0} Page {1} ==> {2}", option.Query, option.Page, ex.Message), ex, NijieException.SEARCH_UNKNOWN_ERROR); } }
public void TestSearchParserMethod() { //var nijie = Nijie.GetInstance(); var option = new NijieSearchOption() { Matching = SearchType.PartialMatch, Query = "無修正", Sort = SortType.Latest, SearchBy = SearchMode.Tag, Page = 1 }; var search = new NijieSearch(option); { var page = UpdateHtmlForm.PATH + "search-tag-partial-latest.html"; Assert.IsTrue(File.Exists(page), "Test file is missing!"); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(File.ReadAllText(page)); var result = nijie.ParseSearch(doc, search); Assert.AreEqual(48, result.Images.Count, "Image counts differents"); foreach (var image in result.Images) { Assert.IsTrue(image.ImageId > 0, "Image Id not valid"); Assert.IsNotNull(image.ThumbImageUrl, "Thumbnail image missing!"); } Assert.IsTrue(result.IsNextAvailable, "Next Page should be available"); Assert.AreEqual(163, result.TotalImages, "Different image count"); } { var page = UpdateHtmlForm.PATH + "search-tag-exact-latest.html"; Assert.IsTrue(File.Exists(page), "Test file is missing!"); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(File.ReadAllText(page)); var result = nijie.ParseSearch(doc, search); Assert.AreEqual(48, result.Images.Count, "Image counts differents"); foreach (var image in result.Images) { Assert.IsTrue(image.ImageId > 0, "Image Id not valid"); Assert.IsNotNull(image.ThumbImageUrl, "Thumbnail image missing!"); } Assert.IsTrue(result.IsNextAvailable, "Next Page should be available"); Assert.AreEqual(104, result.TotalImages, "Different image count"); } { var page = UpdateHtmlForm.PATH + "search-tag-partial-latest-lastpage.html"; Assert.IsTrue(File.Exists(page), "Test file is missing!"); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(File.ReadAllText(page)); search.Option.Page = UpdateHtmlForm.search_tag_partial_latest_lastpage_page; var result = nijie.ParseSearch(doc, search); Assert.AreEqual(18, result.Images.Count, "Image counts differents"); Assert.AreEqual(163, result.TotalImages, "Total Image counts differents"); foreach (var image in result.Images) { Assert.IsTrue(image.ImageId > 0, "Image Id not valid"); Assert.IsNotNull(image.ThumbImageUrl, "Thumbnail image missing!"); } Assert.IsFalse(result.IsNextAvailable, "Next Page should not be available"); Assert.AreEqual(163, result.TotalImages, "Different image count"); } }
private void btnUpdate_Click(object sender, EventArgs e) { txtLog.AppendText("Logging in..." + Environment.NewLine); var result = nijie.Login(txtUser.Text, txtPass.Text); if (result) { txtLog.AppendText("Log In succesfull" + Environment.NewLine); // get index page txtLog.AppendText("Getting index page..." + Environment.NewLine); downloadHelper("https://nijie.info", "index.html"); // get member bookmark page var url = "https://nijie.info/members_illust.php?id=" + MEMBER_1; txtLog.AppendText("Getting member images page..." + Environment.NewLine); downloadHelper(url, "member-images.html"); // get member doujin page url = "https://nijie.info/members_dojin.php?id=" + MEMBER_3; txtLog.AppendText("Getting member images page..." + Environment.NewLine); downloadHelper(url, "member-doujins.html"); // get member bookmark page url = "https://nijie.info/user_like_illust_view.php?id=" + MEMBER_1; txtLog.AppendText("Getting member's bookmarked images page..." + Environment.NewLine); downloadHelper(url, "member-bookmarked-images.html"); // get member bookmark last page url = "https://nijie.info/user_like_illust_view.php?id=" + MEMBER_1 + "&p=2"; txtLog.AppendText("Getting member's bookmarked images last page..." + Environment.NewLine); downloadHelper(url, "member-bookmarked-images-lastpage.html"); // get search page { txtLog.AppendText("Getting search1 page Tag PartialMatch..." + Environment.NewLine); var option = new NijieSearchOption() { Matching = SearchType.PartialMatch, Query = "無修正", Sort = SortType.Latest, SearchBy = SearchMode.Tag }; url = NijieSearch.GenerateQueryUrl(option); downloadHelper(url, "search-tag-partial-latest.html"); } { txtLog.AppendText("Getting search2 page Tag ExactMatch..." + Environment.NewLine); var option = new NijieSearchOption() { Matching = SearchType.ExactMatch, Query = "無修正", Sort = SortType.Latest, SearchBy = SearchMode.Tag }; url = NijieSearch.GenerateQueryUrl(option); downloadHelper(url, "search-tag-exact-latest.html"); } { txtLog.AppendText("Getting search last page Tag PartialMatch..." + Environment.NewLine); var option = new NijieSearchOption() { Matching = SearchType.PartialMatch, Query = "無修正", Sort = SortType.Latest, SearchBy = SearchMode.Tag, Page = search_tag_partial_latest_lastpage_page }; url = NijieSearch.GenerateQueryUrl(option); downloadHelper(url, "search-tag-partial-latest-lastpage.html"); } { txtLog.AppendText("Getting search2 last page Tag ExactMatch..." + Environment.NewLine); var option = new NijieSearchOption() { Matching = SearchType.ExactMatch, Query = "無修正", Sort = SortType.Latest, SearchBy = SearchMode.Tag, Page = 2 }; url = NijieSearch.GenerateQueryUrl(option); downloadHelper(url, "search-tag-exact-latest-lastpage.html"); } // image page { // normal txtLog.AppendText("Getting image page..." + Environment.NewLine); downloadHelper("https://nijie.info/view.php?id=" + IMAGE, "image-normal.html"); // manga txtLog.AppendText("Getting manga page..." + Environment.NewLine); downloadHelper("https://nijie.info/view.php?id=" + MANGA, "image-manga.html"); downloadHelper("https://nijie.info/view_popup.php?id=" + MANGA, "image-manga-popup.html"); downloadHelper("https://nijie.info/view.php?id=" + MANGA2, "image-manga-filter.html"); downloadHelper("https://nijie.info/view_popup.php?id=" + MANGA2, "image-manga-popup-filter.html"); // doujin txtLog.AppendText("Getting doujin page..." + Environment.NewLine); downloadHelper("https://nijie.info/view.php?id=" + DOUJIN, "image-doujin.html"); downloadHelper("https://nijie.info/view_popup.php?id=" + DOUJIN, "image-doujin-popup.html"); // video txtLog.AppendText("Getting doujin page..." + Environment.NewLine); downloadHelper("https://nijie.info/view.php?id=" + VIDEO, "image-video.html"); downloadHelper("https://nijie.info/view_popup.php?id=" + VIDEO, "image-video-popup.html"); } txtLog.AppendText("---====ALL DONE====---" + Environment.NewLine); this.DialogResult = System.Windows.Forms.DialogResult.OK; Properties.Settings.Default.Save(); this.Close(); } }