Ejemplo n.º 1
0
        /// <summary>
        /// 分析文库主页,获得各章URL
        /// </summary>
        /// <param name="url"></param>
        /// <param name="html"></param>
        public override void ProcessMainPage(string url, string html)
        {
            base.MainURL = url;
            string div = getRegEx(html, @"<!--\s*左侧\s*-->([\s\S]*?)<!--\s*右侧\s*-->","$1");
            base.Epub.CoverImg.Url = HOST + getRegEx(div, @"<div class=""lk-book-cover""><a href=""#"" target=""_blank""><img src=""([\s\S]*?)""/>", "$1");
            base.Epub.CoverImg.StoreName = "cover";

            ProcessInfo(div);

            div = getRegEx(html, @"<ul class=""lk-chapter-list unstyled pt-10 pb-10 mt-20"">([\s\S]*)</ul>", "$1", RegexOptions.IgnoreCase, false);
            MatchCollection matchCollection = getRegExs(div, @"<a\s?href=""(?<url>[\s\S]*?)""\s?>([\s\S]*?)<span\s?class=""lk-ellipsis"">(?<text>[\s\S]*?)</span>([\s\S]*?)</a>");
            for (int i = 0; i < matchCollection.Count; i++)
            {
                base.AddPercentageTotal();
                Capater c = new Capater();
                //章标题
                c.Index = i;
                c.Title = base.ClearBlank(matchCollection[i].Groups["text"].Value.Replace("\r", "").Replace("\n", " ").Replace("\t", " ").Replace(" ", " ").Trim());
                c.Url = matchCollection[i].Groups["url"].Value.Trim();
                base.Epub.Capaters.Add(c);
            }

            base.Status = BookStatus.Running;
            CreateWB(base.Epub.Capaters[0]);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建浏览器加载各个章节
        /// </summary>
        /// <param name="c"></param>
        private void CreateWB(Capater c)
        {
            WebBrowser wb = new WebBrowser();
            base.Browsers.Add(wb);
            BroswersLodedIndex++;
            wb.DocumentCompleted += delegate(object sender, WebBrowserDocumentCompletedEventArgs args)
            {
                if (wb != null && IsBroswerOK(wb))
                {
                    c.Html = wb.DocumentText;
                    int a = base.Epub.Capaters.Count;
                    int b = base.Browsers.Count;
                    if (base.Epub.Capaters.Count > base.Browsers.Count)
                    {
                        CreateWB(base.Epub.Capaters[base.Browsers.Count]);
                    }
                    else
                    {
                        Status = BookStatus.BroswerCompleted;
                    }
                    //删除浏览器
                    wb = null;
                    //清理内存
                    IntPtr pHandle = GetCurrentProcess();
                    SetProcessWorkingSetSize(pHandle, -1, -1);

                    base.AddPercentage(PercentageType.PageLoaded);
                }
            };
            wb.Navigate(c.Url);
        }
Ejemplo n.º 3
0
 private static string _getCapaterFileName(Capater capater)
 {
     return _getCapaterFileName(capater, true) + ".xhtml";
 }
Ejemplo n.º 4
0
 private static string _getCapaterFileName(Capater capater,bool noExt)
 {
     if (!noExt)
     {
         return _getCapaterFileName(capater);
     }
     int i = capater.CapaterIndex;
     string capaterIndex = i <= 9 ? "00" : (i <= 99 ? "0" : "");
     capaterIndex += i.ToString();
     string filename = "Section" + capaterIndex;
     return filename;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 将原始的TXT行转换为EPUB行
 /// </summary>
 /// <param name="newBook"></param>
 /// <returns></returns>
 public static Book Text2Epub(Book newBook)
 {
     string _delimiterClass = delimiterClass == "" ? "" : " class='" + delimiterClass.Trim() + "'";
     newBook.capaters = new List<Capater>();
     int capaterIndex = 0; //章节序号
     for (int i = 0; i < newBook.booklines.Count; i++)
     {
         if (IsTitle(newBook.booklines[i]))
         {
             newBook.epublines[i] = DefaultModel.GetSetting("正文标题").Replace("[%标题%]", newBook.booklines[i]);
             Capater cm = new Capater();
             cm.Name = newBook.booklines[i];
             cm.SatrtLine = i;
             cm.CapaterIndex = capaterIndex;
             cm.EndLine = newBook.booklines.Count - 1;
             if (capaterIndex > 0)
             {
                 newBook.capaters[capaterIndex - 1].EndLine = i - 1;
             }
             newBook.capaters.Add(cm);
             capaterIndex++;
         }
         else
         {
             if (IsDelimiter(newBook.booklines[i]))
                 newBook.epublines[i] = "<" + delimiterMark + _delimiterClass + ">" + newBook.booklines[i] + "</" + delimiterMark + ">";//若为分界符
             else
             {
                 newBook.epublines[i] = DefaultModel.GetSetting("正文行").Replace("[%该行内容%]", newBook.booklines[i]);
             }
         }
     }
     return newBook;
 }