Ejemplo n.º 1
0
        static int GenerateEpub30Dtb()
        {
            var startTime = DateTime.Now;

            output = Path.GetFullPath(output);
            if (!".epub".Equals(Path.GetExtension(output), StringComparison.InvariantCultureIgnoreCase))
            {
                Console.WriteLine($"Invalid output path for epub:\n{output}\nMust have .epub extension");
                return(-2);
            }
            if (!input.Equals(output, StringComparison.InvariantCultureIgnoreCase))
            {
                File.Copy(input, output, true);
            }
            var publication = new EpubPublication()
            {
                Path = output
            };

            if (!String.IsNullOrWhiteSpace(identifier))
            {
                publication.SetDcIdentifier(identifier);
            }
            if (!String.IsNullOrWhiteSpace(creator))
            {
                publication.SetMetadata("dc:creator", creator);
            }
            if (!String.IsNullOrWhiteSpace(publisher))
            {
                publication.SetMetadata("dc:publisher", publisher);
            }
            var synthesizer = new EpubSynthesizer()
            {
                Publication = publication,
                Mp3BitRate  = bitrate
            };

            synthesizer.Progress += (sender, args) =>
            {
                Console.Write($"{args.ProgressPercentage:D3}% {args.ProgressMessage}".PadRight(80).Substring(0, 80) + "\r");
            };
            synthesizer.Synthesize();
            Console.Write($"{new String(' ', 80)}\r");
            Console.WriteLine($"Successfully generated ePub 3.0 DTB {output}\nDuration: {DateTime.Now.Subtract(startTime)}");
            publication.Dispose();
            return(0);
        }
Ejemplo n.º 2
0
        public void SynthesizeTests(string epubFile)
        {
            epubFile = ResolvePath(epubFile);
            var output = Path.Combine(TestContext.DeploymentDirectory, "EpubOutput", Path.GetFileName(epubFile) ?? "");

            if (!Directory.Exists(Path.GetDirectoryName(output)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(output) ?? "");
            }
            File.Copy(epubFile, output, true);
            TestContext.AddResultFile(output);
            using (var epubPub = new EpubPublication()
            {
                Path = output
            })
            {
                var synth = new EpubSynthesizer()
                {
                    Publication = epubPub
                };
                var headerNames = Enumerable.Range(1, 6).Select(i => Utils.XhtmlNs + $"h{i}").ToList();
                synth.Synthesize();
                Assert.AreEqual(
                    synth.Publication.XhtmlDocuments.Count(),
                    synth.Publication.FileUris.Count(uri => uri.AbsolutePath.EndsWith(".smil")),
                    "Expected one smil file per xhtml file");
                Assert.AreEqual(
                    synth.Publication.XhtmlDocuments.SelectMany(doc => doc.Descendants()).Count(e => headerNames.Contains(e.Name)),
                    synth.Publication.FileUris.Count(uri => uri.AbsolutePath.EndsWith(".mp3")),
                    "Expected one audio file per xhtml file");
                Assert.AreEqual(
                    synth.Publication.XhtmlDocuments.SelectMany(doc => doc.Descendants()).Count(e => headerNames.Contains(e.Name)),
                    synth.Publication.PackageFile.Descendants(Utils.OpfNs + "item").Count(item => item.Attribute("href")?.Value?.EndsWith(".mp3") ?? false),
                    "Expected one mp3 item in manifest per xhtml file");
                Assert.AreEqual(
                    synth.Publication.XhtmlDocuments.Count(),
                    synth.Publication.PackageFile.Descendants(Utils.OpfNs + "item").Count(item => item.Attribute("href")?.Value?.EndsWith(".smil") ?? false),
                    "Expected one smil item in manifest per xhtml file");
            }
        }