/// <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 static string GenerateQueryUrl(NijieSearchOption option)
 {
     var url = String.Format(@"//nijie.info/search.php?type={0}&word={1}&p={2}&mode={3}&illust_type={4}&sort={5}"
             , option.SearchTypeStr
             , option.Query
             , (int)option.Page
             , (int)option.SearchBy
             , ""
             , (int)option.Sort);
     return Util.FixUrl(url, Nijie.ROOT_DOMAIN, Properties.Settings.Default.UseHttps);
 }
Exemple #3
0
        public static string GenerateQueryUrl(NijieSearchOption option)
        {
            var url = String.Format(@"//nijie.info/search.php?type={0}&word={1}&p={2}&mode={3}&illust_type={4}&sort={5}"
                                    , option.SearchTypeStr
                                    , option.Query
                                    , (int)option.Page
                                    , (int)option.SearchBy
                                    , ""
                                    , (int)option.Sort);

            return(Util.FixUrl(url, Nijie.ROOT_DOMAIN, Properties.Settings.Default.UseHttps));
        }
        public void OnFragmentNavigation(FirstFloor.ModernUI.Windows.Navigation.FragmentNavigationEventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(e.Fragment))
            {
                var uri = new Uri("http://localhost/?" + e.Fragment);
                var query = System.Web.HttpUtility.ParseQueryString(uri.Query);
                if (query.Get("type").Equals("member"))
                {
                    int mode = 0;
                    var modeStr = query.Get("mode");
                    if (modeStr != null)
                    {
                        Int32.TryParse(modeStr, out mode);
                    }
                    var memberIds = query.Get("memberId");
                    var ids = memberIds.Split(',');
                    int i = 1;
                    foreach (var memberId in ids)
                    {
                        var message = String.Format("{0} of {1}", i, ids.Count());
                        addJobForMember(Int32.Parse(memberId), (MemberMode)mode, message);
                        i++;
                    }
                }
                else if (query.Get("type").Equals("search"))
                {
                    var tags = query.Get("tags");
                    var page = query.Get("page");
                    var sort = query.Get("sort");
                    var mode = query.Get("mode");
                    var type = query.Get("searchType");

                    NijieSearchOption option = new NijieSearchOption()
                    {
                        Query = tags,
                        Page = Int32.Parse(page),
                        Sort = (SortType)Enum.Parse(typeof(SortType), sort),
                        SearchBy = (SearchMode)Enum.Parse(typeof(SearchMode), mode),
                        Matching = (SearchType)Enum.Parse(typeof(SearchType), type)
                    };
                    addJobForSearch(option);
                }
                else if (query.Get("type").Equals("image"))
                {
                    var imageIds = query.Get("imageId");
                    var ids = imageIds.Split(',');
                    foreach (var imageId in ids)
                    {
                        addJobForImage(Int32.Parse(imageId));
                    }
                }
            }
        }
 private void addJobForSearch(NijieSearchOption option)
 {
     var newJob = new JobDownloadViewModel();
     newJob.JobType = JobType.Tags;
     newJob.SearchTag = option.Query;
     newJob.Status = JobStatus.Added;
     newJob.StartPage = option.Page;
     newJob.Sort = option.Sort;
     newJob.Matching = option.Matching;
     newJob.SearchBy = option.SearchBy;
     var result = ShowAddJobDialog(newJob);
     if (result != null)
     {
         AddJob(result);
     }
 }
        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
                txtLog.AppendText("Getting member images page..." + Environment.NewLine);
                downloadHelper("https://nijie.info/members_illust.php?id=" + MEMBER_1, "member-images.html");

                // get member doujin page
                txtLog.AppendText("Getting member images page..." + Environment.NewLine);
                downloadHelper("https://nijie.info/members_dojin.php?id=" + MEMBER_2, "member-doujins.html");

                // get member bookmark page
                txtLog.AppendText("Getting member's bookmarked images page..." + Environment.NewLine);
                downloadHelper("https://nijie.info/user_like_illust_view.php?id=" + MEMBER_1, "member-bookmarked-images.html");

                // get member bookmark last page
                txtLog.AppendText("Getting member's bookmarked images last page..." + Environment.NewLine);
                downloadHelper("https://nijie.info/user_like_illust_view.php?id=" + MEMBER_1 + "&p=2", "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
                    };
                    downloadHelper(NijieSearch.GenerateQueryUrl(option), "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
                    };
                    downloadHelper(NijieSearch.GenerateQueryUrl(option), "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
                    };
                    downloadHelper(NijieSearch.GenerateQueryUrl(option), "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
                    };
                    downloadHelper(NijieSearch.GenerateQueryUrl(option), "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");
                }

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                Properties.Settings.Default.Save();
                this.Close();
            }
            txtLog.AppendText("---====ALL DONE====---" + Environment.NewLine);
        }
Exemple #7
0
 public NijieSearch(NijieSearchOption option)
 {
     this.Option = option;
 }
Exemple #8
0
        /// <summary>
        /// Process images from search result.
        /// </summary>
        /// <param name="job"></param>
        private void doSearchJob(JobDownloadViewModel job)
        {
            if (isJobCancelled(job)) return;

            MainWindow.Log.Debug("Running Search Job: " + job.Name);
            try
            {
                job.CurrentPage = job.StartPage;
                int endPage = job.EndPage;
                int limit = job.Limit;
                bool flag = true;

                job.DownloadCount = 0;

                while (flag)
                {
                    if (isJobCancelled(job)) return;

                    job.Message = "Parsing search page: " + job.CurrentPage;
                    var option = new NijieSearchOption()
                    {
                        Query = job.SearchTag,
                        Page = job.CurrentPage,
                        Sort = job.Sort,
                        Matching = job.Matching,
                        SearchBy = job.SearchBy
                    };
                    var searchPage = MainWindow.Bot.Search(option);

                    job.TotalImages = searchPage.TotalImages;

                    if (searchPage.Images == null || searchPage.Images.Count == 0)
                    {
                        job.Message = "No more images found!";
                        return;
                    }

                    foreach (var image in searchPage.Images)
                    {
                        if (isJobCancelled(job)) return;

                        if (image.IsFriendOnly || image.IsGoldenMember)
                        {
                            job.Message = String.Format("Skipping ImageId: {0} because locked", image.ImageId);
                            continue;
                        }

                        try
                        {
                            processImage(job, null, image);
                        }
                        catch (NijieException ne)
                        {
                            if (ne.ErrorCode == NijieException.DOWNLOAD_ERROR)
                            {
                                job.Exceptions.Add(ne);
                                continue;
                            }
                            else
                                throw;
                        }

                        if (job.DownloadCount > limit && limit != 0)
                        {
                            job.Message = "Image limit reached: " + limit;
                            return;
                        }
                    }

                    ++job.CurrentPage;
                    MainWindow.Log.Info("Moving to next page: " + job.CurrentPage);
                    if (job.CurrentPage > endPage && endPage != 0)
                    {
                        job.Message = "Page limit reached: " + endPage;
                        return;
                    }
                    else if (job.DownloadCount > limit && limit != 0)
                    {
                        job.Message = "Download count reached: " + limit;
                        return;
                    }
                    flag = searchPage.IsNextAvailable;
                }
            }
            catch (NijieException ne)
            {
                HandleJobException(job, ne);
                MainWindow.Log.Error("Error when processing Search Job: " + job.Name, ne);
            }
        }
Exemple #9
0
        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(160, 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(88, 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(15, 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.IsFalse(result.IsNextAvailable, "Next Page should not be available");
                Assert.AreEqual(160, result.TotalImages, "Different image count");
            }
        }
        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;
            }
        }
 public NijieSearch(NijieSearchOption option)
 {
     this.Option = option;
 }