示例#1
0
        public void ParseChapter()
        {
            ChapterModel _parseChapterResult = new ChapterModel();

            _parseChapterResult.ImageUrl = "http://testsite.com";
            _parseChapterResult.NextUrl  = "mailto:[email protected]";

            var result = _objParse.GetChapterLinks(_html.ToString());

            Assert.AreEqual(_parseChapterResult, result);
        }
        /// <param name="ChapterStartUrl">URL for First Page of Chapter</param>
        /// <param name="NextChapterUrl">URL for First Page of Next Chapter</param>
        /// <param name="FilePath">Path to save Chapter</param>
        public async Task DownloadFullChapter(Uri ChapterStartUrl, string NextChapterUrl, string FilePath)
        {
            Uri  NextLinkUrl       = ChapterStartUrl;
            bool LoopAgain         = true;
            bool HasNextChapterUrl = !string.IsNullOrWhiteSpace(NextChapterUrl);
            int  ChapterPageNo     = 1;

            do
            {
                //Download Html document
                string doc = await _download.LoadDocumentAsync(NextLinkUrl).ConfigureAwait(false);

                //Parse the Html document to get List of Series
                var result = _parseHtml.GetChapterLinks(doc);
                //Download Image
                Uri ImageUrl = new Uri(result.ImageUrl);
                await _download.SaveImgAsync(ImageUrl, Path.Combine(FilePath, ChapterPageNo.ToString()));

                if (HasNextChapterUrl)
                {
                    /***
                     * If No Next is found OR Next Url is same as Starting Url,
                     * Exit the Loop, Otherwise Assign it to 'NextLinkUrl' variable
                     ***/
                    if (result.NextUrl.Equals(string.Empty) &&
                        result.NextUrl.Equals(NextChapterUrl, StringComparison.OrdinalIgnoreCase))
                    {
                        LoopAgain = false;
                    }
                    else
                    {
                        NextLinkUrl = new Uri(result.NextUrl);
                    }
                }
            } while (LoopAgain);
        }