コード例 #1
0
        private Daisy202Synthesizer GetDaisy202Synthesizer(string xhtmlFile, bool encodeMp3 = false)
        {
            xhtmlFile = Path.Combine(TestContext.DeploymentDirectory, xhtmlFile);
            TestContext.AddResultFile(xhtmlFile);
            var synthesizer = new Daisy202Synthesizer()
            {
                XhtmlDocument = XDocument.Load(xhtmlFile, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo),
                EncodeMp3     = encodeMp3
            };

            if (synthesizer.Body.Elements().Select(Utils.SetMissingIds).Sum() > 0)
            {
                synthesizer.XhtmlDocument.Save(
                    new Uri(synthesizer.XhtmlDocument.BaseUri).LocalPath);
            }
            return(synthesizer);
        }
コード例 #2
0
        private static int Synthesize()
        {
            var sourceFileName = Path.Combine(DestPath, $"{sourceTitleNumber}.xml");

            if (!File.Exists(sourceFileName))
            {
                logger.Error($"Could not find source file {sourceFileName}");
                return(-1);
            }
            XDocument dtbook;

            try
            {
                dtbook = XDocument.Load(sourceFileName, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
            }
            catch (Exception e)
            {
                logger.Error(e, $"Could not load source file {sourceFileName}");
                return(-1);
            }
            var xhtmlFileName = Path.Combine(DestPath, $"{destTitleNumber}.html");

            Utils.SetMeta(dtbook, "dc:identifier", $"dk-nota-{destTitleNumber}");
            Utils.TransformDtbookToXhtml(dtbook).Save(xhtmlFileName);
            if (File.Exists(sourceFileName))
            {
                File.Delete(sourceFileName);
            }
            var synthesizer = new Daisy202Synthesizer()
            {
                XhtmlDocument = XDocument.Load(xhtmlFileName, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo),
                EncodeMp3     = true,
                Mp3BitRate    = bitrate
            };

            synthesizer.Progress += (sender, args) =>
            {
                Console.Write($"{args.ProgressPercentage:D3}% {args.ProgressMessage}".PadRight(80).Substring(0, 80) + "\r");
            };
            synthesizer.GenerateDtb();
            Console.Write($"{new String(' ', 80)}\r");
            logger.Info("Synthesized DTB");
            return(0);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Notalib/DtbTools
        static int GenerateDaisy202Dtb(XDocument xhtmlDocument)
        {
            var startTime = DateTime.Now;

            output = Path.GetFullPath(output);
            if (!Directory.Exists(output))
            {
                Directory.CreateDirectory(output);
            }
            if (!String.IsNullOrWhiteSpace(identifier))
            {
                Utils.SetMeta(xhtmlDocument, "dc:identifier", identifier);
            }
            if (String.IsNullOrWhiteSpace(Utils.GetMetaContent(xhtmlDocument, "dc:creator")))
            {
                Utils.SetMeta(xhtmlDocument, "dc:creator", creator);
            }
            if (String.IsNullOrWhiteSpace(Utils.GetMetaContent(xhtmlDocument, "dc:publisher")))
            {
                Utils.SetMeta(xhtmlDocument, "dc:publisher", publisher);
            }
            var synthesizer = new Daisy202Synthesizer()
            {
                XhtmlDocument = xhtmlDocument,
                EncodeMp3     = mp3,
                Mp3BitRate    = bitrate
            };

            synthesizer.Progress += (sender, args) =>
            {
                Console.Write($"{args.ProgressPercentage:D3}% {args.ProgressMessage}".PadRight(80).Substring(0, 80) + "\r");
            };
            synthesizer.GenerateDtb();
            Console.Write($"{new String(' ', 80)}\r");
            Console.WriteLine($"Successfully generated Daisy 2.02 DTB in {output}\nDuration: {DateTime.Now.Subtract(startTime)}");
            return(0);
        }