Exemplo n.º 1
0
        /// <summary>
        /// 直接下載一冊txt檔案至指定路徑
        /// </summary>
        public async Task <bool> DownloadIssueAsync(IssueLink issueLink, string path)
        {
            try
            {
                if (!path.EndsWith(".txt"))
                {
                    path += ".txt";
                }
                string firstChapterUrl = issueLink.ChapterLinks.First().Url;
                var(aidString, vidString) = ParseAidVid(firstChapterUrl);
                // vid -1
                if (int.TryParse(vidString, out int vid))
                {
                    vid--;
                    string download = $"http://dl.wenku8.com/packtxt.php?aid={aidString}&vid={vid}&charset=big5";
                    Uri    uri      = new Uri(download);
                    using (WebClient client = new WebClient())
                    {
                        await client.DownloadFileTaskAsync(uri, path);
                    }
                    return(true);
                }
                Console.WriteLine("Cannot parse vid: " + vidString);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 下載一冊書
        /// </summary>
        public async Task <Issue> GetIssueAsync(IssueLink issueLink, CodePage codePage)
        {
            if (issueLink == null || issueLink.ChapterLinks.Count == 0)
            {
                return(null);
            }

            Issue issue = new Issue();

            issue.Title = issueLink.Title;
            foreach (var chapterLink in issueLink.ChapterLinks)
            {
                if (OnlyReturnNew)
                {
                    if (!chapterLink.Downloaded || string.IsNullOrEmpty(chapterLink.Content))
                    {
                        issue.Chapters.Add(await GetChapterContent(chapterLink, codePage));
                    }
                }
                else
                {
                    issue.Chapters.Add(await GetChapterContent(chapterLink, codePage));
                }
                await Task.Delay(SLEEP_MS);
            }

            return(issue);
        }
Exemplo n.º 3
0
        protected override BookLink GetChapterLinks(HtmlDocument htmlDoc, string baseUrl)
        {
            var titleNode  = htmlDoc.DocumentNode.SelectSingleNode("//div[@id='title']");
            var authorNode = htmlDoc.DocumentNode.SelectSingleNode("//div[@id='info']");

            BookLink bookLink = new BookLink
            {
                IndexPage = baseUrl,
                Title     = Utilities.ToTraditional(titleNode?.InnerText),
                Author    = authorNode?.InnerText
            };

            baseUrl = Utilities.TrimEnd(baseUrl.ToLower(), "index.htm");

            List <HtmlNode> tableRows = new List <HtmlNode>();
            var             tables    = htmlDoc.DocumentNode.SelectNodes("//table[@class='css']");

            foreach (var tableNode in tables)
            {
                tableRows.AddRange(tableNode.Descendants("tr"));
            }

            List <IssueLink> issueLinks = new List <IssueLink>();

            foreach (var node in tableRows)
            {
                var titleRow = node.SelectSingleNode(".//td[@class='vcss']");
                if (titleRow != null)
                {
                    IssueLink b = new IssueLink
                    {
                        Title = Utilities.ToTraditional(titleRow.InnerText)
                    };
                    issueLinks.Add(b);
                    continue;
                }

                // 一個章節的 tr 裡面會有一個以上的 ccss 文章超連結
                var chapterRows = node.SelectNodes(".//td[@class='ccss']");
                foreach (var chapterRow in chapterRows)
                {
                    var link = chapterRow.Descendants("a").FirstOrDefault();
                    if (link != null)
                    {
                        ChapterLink chapterLink = new ChapterLink();
                        chapterLink.Title = Utilities.ToTraditional(link.InnerText);
                        chapterLink.Url   = baseUrl + link.Attributes["href"]?.Value;
                        issueLinks.Last()?.ChapterLinks.Add(chapterLink);
                    }
                }
            }

            bookLink.IssueLinks = issueLinks;
            return(bookLink);
        }
        /// <summary>
        /// 下載一冊書
        /// </summary>
        public async Task <Issue> GetIssueAsync(IssueLink issueLink)
        {
            if (issueLink == null || issueLink.ChapterLinks.Count == 0)
            {
                return(null);
            }

            Issue issue = new Issue();

            issue.Title = issueLink.Title;
            foreach (var chapterLink in issueLink.ChapterLinks)
            {
                issue.Chapters.Add(await GetChapterContent(chapterLink.Url));
                await Task.Delay(SLEEP_MS);
            }

            return(issue);
        }
Exemplo n.º 5
0
 public void TryAddNewIssues(BookLink newBook)
 {
     if (newBook == null || object.ReferenceEquals(this, newBook))
     {
         return;
     }
     if (newBook.IndexPage == IndexPage)
     {
         foreach (var newIssueLink in newBook.IssueLinks)
         {
             IssueLink sameIssue = IssueLinks.FirstOrDefault(i => i.Title == newIssueLink.Title && i.IndexNumber == newIssueLink.IndexNumber);
             if (sameIssue == null)
             {   // 沒有同一冊,直接加入
                 IssueLinks.Add(newIssueLink);
             }
             else
             {   // 有同一冊,但是內部章節需要更新
                 sameIssue.TryAddNewChapters(newIssueLink);
             }
         }
     }
 }