示例#1
0
    public void Proc()
    {
        TextTranslation trans = null;

        Log.Note("Epub2Comment");

        if (!string.IsNullOrEmpty(glossaryDocPath))
        {
            trans = new GlossaryImportation(glossaryDocPath);
        }
        else if (castBlackTranslatingMagic)
        {
            trans = new BlackTranslationMagic();
        }
        if (trans != null)
        {
            Log.Note("Text Translation Method: " + trans.ToString());
        }



        Directory.CreateDirectory(output_path);
        try
        {
            if (epub.toc.mediaType == "application/x-dtbncx+xml")
            {
                Parse2();
            }
            else
            {
                Parse3();
            }
        }
        catch (Exception)
        {
            Log.Warn("尝试序列化失败。");
            tocTree = null;
        }

        var plain = GetPlainStruct();

        for (int i = 0; i < plain.Length; i++)
        {
            var t   = epub.spine[i].item.GetFile() as TextEpubItemFile;
            var txt = Html2Comment.ProcXHTML(t.text, trans);
            var p   = output_path + "i" + Util.Number(i, 2) + "_" + Path.GetFileNameWithoutExtension(t.fullName) + Util.FilenameCheck(plain[i]) + ".txt";
            File.WriteAllText(p, txt);
            Log.Note(p);
        }
    }
示例#2
0
    static void Main(string[] args)
    {
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.WriteLine("AeroNovelTool by AE Ver." + Version.date);
        Console.ForegroundColor = ConsoleColor.White;
        if (args.Length >= 2)
        {
            switch (args[0].ToLower())
            {
            case "epub":
            {
                if (!DirectoryExist(args[1]))
                {
                    return;
                }
                var gen = new AeroNovelEpub.GenEpub();
                for (int i = 2; i < args.Length; i++)
                {
                    if (args[i] == "t2s")
                    {
                        gen = new AeroNovelEpub.GenEpub(AeroNovelEpub.ChineseConvertOption.T2S);
                    }
                }

                EpubFile      e          = gen.Gen(args[1]);
                List <string> creators   = new List <string>();
                string        dateString = DateTime.Today.ToString("yyyyMMdd");
                e.dc_creators.ForEach((x) =>
                    {
                        if (x.refines.Count > 0)
                        {
                            foreach (var refine in x.refines)
                            {
                                if (refine.name == "role")
                                {
                                    if (refine.value != "aut")
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        creators.Add(x.value);
                    });
                try
                {
                    e.meta.ForEach((x) => { if (x.name == "dcterms:modified")
                                            {
                                                dateString = x.value.Replace("-", "").Substring(0, 8);
                                            }
                                   });
                }
                catch (ArgumentOutOfRangeException)
                {
                    Log.Warn("Error at getting modified date in metadata");
                }

                e.filename = $"[{string.Join(",", creators)}] {e.title} [{dateString}]";
                if (args.Length >= 3 && DirectoryExist(args[2]))
                {
                    e.Save(args[2]);
                }
                else
                {
                    e.Save("");
                }
            }
            break;

            case "txt":
                if (!DirectoryExist(args[1]))
                {
                    return;
                }
                GenTxt.Gen(args[1]);
                break;

            case "bbcode":
                if (!DirectoryExist(args[1]))
                {
                    return;
                }
                if (args.Length >= 3)
                {
                    if (DirectoryExist(args[2]))
                    {
                        GenBbcode.output_path        = Path.Combine(args[2], GenBbcode.output_path);
                        GenBbcode.output_path_single = Path.Combine(args[2], GenBbcode.output_path_single);
                    }
                }
                GenBbcode.GenSingle(args[1]);
                break;

            case "epub2comment":
                if (!FileExist(args[1]))
                {
                    return;
                }
                Epub2Comment e2c = new Epub2Comment(args[1]);
                if (args.Length > 2)
                {
                    switch (args[2])
                    {
                    case "BlackTranslatingMagic":
                        e2c.castBlackTranslatingMagic = true;
                        break;

                    case "Glossary":
                        if (args.Length > 3)
                        {
                            e2c.glossaryDocPath = args[3];
                        }
                        else
                        {
                            Log.Error("Should give glossary document.");
                        }
                        break;
                    }
                }
                e2c.Proc();
                break;

            case "epub2atxt":
                if (!FileExist(args[1]))
                {
                    return;
                }
                Epub2Atxt.Proc(args[1]);
                break;

            case "html2comment":
                if (!FileExist(args[1]))
                {
                    return;
                }
                Html2Comment.Proc(args[1]);
                break;

            case "atxt2bbcode":
                if (!FileExist(args[1]))
                {
                    return;
                }
                GenBbcode.Proc(args[1]);
                break;

            case "kakuyomu2comment":
            {
                var xhtml = WebSource.KakuyomuEpisode(args[1]);
                var atxt  = Html2Comment.ProcXHTML(xhtml.text);
                File.WriteAllText("output_kakuyomu2comment.txt", atxt);
                Log.Note("output_kakuyomu2comment.txt");
            }
            break;

            case "websrc":
            {
                TextEpubItemFile[] xhtmls;
                string             dirname = "output_websrc_";
                if (args[1].Contains("kakuyomu.jp"))
                {
                    xhtmls   = WebSource.KakuyomuAuto(args[1]);
                    dirname += "kakuyomu";
                }
                else
                {
                    Log.Error("什么网站");
                    break;
                }
                if (xhtmls != null)
                {
                    Directory.CreateDirectory(dirname);
                    foreach (var xhtml in xhtmls)
                    {
                        Save(xhtml, dirname);
                    }
                }
            }
            break;

            case "atxtcc":
            {
                if (!FileExist(args[1]))
                {
                    return;
                }
                bool t2s = false, s2t = false, replace = false;
                for (int i = 2; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "t2s": t2s = true; break;

                    case "s2t": s2t = true; break;

                    case "replace": replace = true; break;
                    }
                }
                if (t2s)
                {
                    AeroNovelEpub.AtxtChineseConvert.ProcT2C(args[1], replace);
                }
                else if (s2t)
                {
                    //Not Implemented
                }
            }
            break;

            default:
                Log.Warn("Nothing happens. " + usage);
                break;
            }
        }
        else
        {
            Log.Warn(usage);
        }
    }