Esempio n. 1
0
        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 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);
            }
        }
Esempio n. 4
0
        /// <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);
            }
        }
Esempio n. 5
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(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();
            }
        }
Esempio n. 7
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;
                    MainWindow.Log.Info("Processing 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
                        {
#if DEBUG
                            job.Message = "Image " + image.ImageId;
                            job.DownloadCount++;
#else
                            processImage(job, null, image);
#endif
                        }
                        catch (NijieException ne)
                        {
                            if (ne.ErrorCode == NijieException.DOWNLOAD_ERROR)
                            {
                                job.Exceptions.Add(ne);
                                MainWindow.Log.Error(String.Format("Error when processing Image: {0}", image.ImageId), ne);
                                continue;
                            }
                            else
                            {
                                throw;
                            }
                        }

                        if (job.DownloadCount > limit && limit != 0)
                        {
                            job.Message = "Image limit reached: " + limit;
                            MainWindow.Log.Info(job.Message + " for Job: " + job.SearchTag);
                            return;
                        }
                    }

                    ++job.CurrentPage;
                    if (job.CurrentPage > endPage && endPage != 0)
                    {
                        job.Message = "Page limit reached: " + endPage;
                        MainWindow.Log.Info(job.Message + " for Job: " + job.SearchTag);
                        return;
                    }
                    else if (job.DownloadCount > limit && limit != 0)
                    {
                        job.Message = "Download count reached: " + limit;
                        MainWindow.Log.Info(job.Message + " for Job: " + job.SearchTag);
                        return;
                    }
                    flag = searchPage.IsNextAvailable;
                    if (!flag)
                    {
                        MainWindow.Log.Info("No more image for Job: " + job.SearchTag);
                    }
                }
            }
            catch (NijieException ne)
            {
                HandleJobException(job, ne);
                MainWindow.Log.Error("Error when processing Search Job: " + job.Name, ne);
            }
        }