Ejemplo n.º 1
0
        // [ → ※[#始め角括弧、1-1-46]
        // ] → ※[#終わり角括弧、1-1-47]
        // 〔 → ※[#始めきっこう(亀甲)括弧、1-1-44]
        // 〕 → ※[#終わりきっこう(亀甲)括弧、1-1-45]
        // | → ※[#縦線、1-1-35]
        // # → ※[#井げた、1-1-84]

        public static void getNovelInfo(string ncode)
        {
            using (var cn = new SQLiteConnection(DbMng.getConnectionString()))
            {
                cn.Open();
                cn.ChangePassword("");
                using (var trans = cn.BeginTransaction())
                {
                    var novelid = DbMng.getNovelId(ncode, cn);
                    var html    = HtmlMng.getNovel(ncode);

                    if (novelid < 0)
                    {
                        novelid = DbMng.addNovelList(ncode, html, cn);
                    }
                    else
                    {
                        DbMng.updateNovelList(novelid, html, cn);
                    }

                    var htmlDoc = new HtmlAgilityPack.HtmlDocument();
                    htmlDoc.LoadHtml(html);
                    DbMng.deleteSubtitleByNovelId(novelid, cn);

                    var articles = htmlDoc.DocumentNode
                                   .SelectNodes(@"//div[@class=""index_box""]/dl[@class=""novel_sublist2""]");
                    var i = 0;
                    foreach (var a in articles)
                    {
                        i++;

                        var htmldl = new HtmlAgilityPack.HtmlDocument();
                        htmldl.LoadHtml(a.InnerHtml);

                        var dd = htmldl.DocumentNode.SelectNodes(@"//dd[@class=""subtitle""]/a")
                                 .Select(x => new
                        {
                            Url   = x.Attributes["href"].Value.Trim(),
                            Title = x.InnerText.Trim(),
                        }).ToList().FirstOrDefault();
                        var url     = dd.Url;
                        var title   = dd.Title;
                        var upddate = htmldl.DocumentNode.SelectNodes(@"//dt[@class=""long_update""]")
                                      .Select(x => x.InnerText.Trim())
                                      .ToList().FirstOrDefault().Substring(0, 16);
                        var pageSplit = url.Split('/');
                        var subhtml   = HtmlMng.getNovel(ncode, pageSplit[2]);
                        DbMng.addSubtitle(i, novelid, dd.Title, dd.Url, subhtml, upddate, cn);
                    }
                    trans.Commit();
                }
                cn.Close();
            }
        }
Ejemplo n.º 2
0
 static public string getConnectionString()
 {
     return(getConnectionString(DbMng.getDBPath()));
 }
Ejemplo n.º 3
0
        public static void outputNovelText(string ncode)
        {
            var filename = ncode + ".txt";
            var dirpath  = Path.Combine(createProjectDirPath(), "tmp");

            if (!Directory.Exists(dirpath))
            {
                Directory.CreateDirectory(dirpath);
            }

            var filepath = Path.Combine(dirpath, filename);

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }

            using (var sw = new StreamWriter(filepath, true, Encoding.GetEncoding("utf-8")))
            {
                using (var aConnection = DbMng.getConnection())
                {
                    var novelists       = DbMng.getNovelList(ncode, aConnection);
                    var subtitles       = DbMng.getSubTitleByNovelId((int)novelists.Id, aConnection);
                    var novelsettings   = DbMng.getNovelSetting((int)novelists.Id, aConnection);
                    var replacesettings = DbMng.getReplaceSetting((int)novelists.Id, aConnection);
                    var repflg          = novelsettings.Replacestring;

                    var title = repflg ? repNStr(novelists.Title, replacesettings) : novelists.Title;
                    sw.WriteLine(title);
                    var writername = repflg ? repNStr(novelists.Writername, replacesettings) : novelists.Writername;
                    sw.WriteLine(BRINGEND_CHAR_3 + writername);

                    var captertitle = "";
                    foreach (var subtitle in subtitles)
                    {
                        if (!subtitle.Output)
                        {
                            continue;
                        }

                        if (captertitle != subtitle.Capter)
                        {
                            sw.WriteLine(LITERATURE);
                            sw.WriteLine(TEXT_CENTER + HEADLINE.LINE.L.START + subtitle.Capter + HEADLINE.LINE.L.END);
                            captertitle = subtitle.Capter;
                        }


                        var htmlDoc = new HtmlAgilityPack.HtmlDocument();
                        htmlDoc.LoadHtml(subtitle.Html);

                        sw.WriteLine(LITERATURE);

                        var repsubtitle = repflg ? repNStr(subtitle.Title, replacesettings) : subtitle.Title;
                        if (novelsettings.Subtitleheading)
                        {
                            sw.WriteLine(TEXT_CENTER + HEADLINE.LINE.M.START + repsubtitle + HEADLINE.LINE.M.END);
                        }
                        else
                        {
                            sw.WriteLine(repsubtitle);
                        }
                        sw.WriteLine("");

                        if (novelsettings.Preface)
                        {
                            var nodenovelp = htmlDoc.DocumentNode.SelectSingleNode(@"//div[@id=""novel_p""]");
                            var novelp     = nodenovelp == null ? null : nodenovelp.InnerText;
                            if (!String.IsNullOrEmpty(novelp))
                            {
                                sw.WriteLine(INDENTATION.BLOCK.START_2 + CHARSIZE_LEVEL_DOWN.BLOCK.START_2 + RULED_LINE_ENCLOSURE.START);
                                outputText(novelp, repflg, replacesettings, novelsettings, sw);
                                sw.WriteLine(RULED_LINE_ENCLOSURE.END);
                                sw.WriteLine(CHARSIZE_LEVEL_DOWN.BLOCK.END + INDENTATION.BLOCK.END);
                            }
                        }

                        var nodenovelh = htmlDoc.DocumentNode.SelectSingleNode(@"//div[@id=""novel_honbun""]");
                        var novelh     = nodenovelh == null ? null : nodenovelh.InnerText;
                        if (novelh != null)
                        {
                            outputText(novelh, repflg, replacesettings, novelsettings, sw);
                        }

                        if (novelsettings.Preface)
                        {
                            var nodenovela = htmlDoc.DocumentNode.SelectSingleNode(@"//div[@id=""novel_a""]");
                            var novela     = nodenovela == null ? null : nodenovela.InnerText;
                            if (!String.IsNullOrEmpty(novela))
                            {
                                sw.WriteLine(INDENTATION.BLOCK.START_2 + CHARSIZE_LEVEL_DOWN.BLOCK.START_2 + RULED_LINE_ENCLOSURE.START);
                                outputText(novela, repflg, replacesettings, novelsettings, sw);
                                sw.WriteLine(RULED_LINE_ENCLOSURE.END);
                                sw.WriteLine(CHARSIZE_LEVEL_DOWN.BLOCK.END + INDENTATION.BLOCK.END);
                            }
                        }
                    }
                }
            }
        }