Exemplo n.º 1
0
 public void XhtmlDocumentsTests(string epubFile)
 {
     epubFile = ResolvePath(epubFile);
     using (var epubPublication = new EpubPublication()
     {
         Path = epubFile
     })
     {
         Assert.AreEqual(
             epubPublication.PackageFile?.Descendants(Utils.OpfNs + "item").Count(item =>
                                                                                  item.Attribute("media-type")?.Value == "application/xhtml+xml") ?? 0,
             epubPublication.XhtmlDocuments.Count(),
             "Unexpected number of Xhtml documents");
         Assert.AreEqual(
             epubPublication.PackageFile
             ?.Descendants(Utils.OpfNs + "item")
             .Where(item =>
                    (item.Attribute("media-type")?.Value ?? "") == "application/xhtml+xml" &&
                    (item.Attribute("properties")?.Value ?? "") == "nav")
             .Select(item => new Uri(epubPublication.PackageFileUri, item.Attribute("href")?.Value ?? ""))
             .Single(),
             new Uri(epubPublication.XhtmlDocuments.First().BaseUri),
             "First XhtmlDocument is not nav document");
     }
 }
Exemplo n.º 2
0
 public void PackageFileTests(string epubFile)
 {
     epubFile = ResolvePath(epubFile);
     using (var epubPublication = new EpubPublication()
     {
         Path = epubFile
     })
     {
         Assert.IsNotNull(epubPublication.PackageFileUri);
         Assert.AreEqual(epubPublication.PackageFileUri.AbsoluteUri, epubPublication.PackageFile.BaseUri, "Package file has wrong base uri");
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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");
            }
        }