Skip to content

Commit

Permalink
EPUB 3.3 support (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
vers-one authored May 13, 2023
1 parent 148e71a commit 7c75acc
Show file tree
Hide file tree
Showing 36 changed files with 955 additions and 274 deletions.
1 change: 1 addition & 0 deletions Source/VersOne.Epub.Test/Comparers/EpubContentComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void CompareEpubContents(EpubContent expected, EpubContent actual)
CompareContentCollections(expected.Css, actual.Css, CompareEpubLocalTextContentFiles, CompareEpubRemoteTextContentFiles);
CompareContentCollections(expected.Images, actual.Images, CompareEpubLocalByteContentFiles, CompareEpubRemoteByteContentFiles);
CompareContentCollections(expected.Fonts, actual.Fonts, CompareEpubLocalByteContentFiles, CompareEpubRemoteByteContentFiles);
CompareContentCollections(expected.Audio, actual.Audio, CompareEpubLocalByteContentFiles, CompareEpubRemoteByteContentFiles);
CompareContentCollections(expected.AllFiles, actual.AllFiles, CompareLocalEpubContentFilesWithContent, CompareRemoteEpubContentFilesWithContent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void CompareEpubContentRefs(EpubContentRef expected, EpubContentRe
CompareContentCollectionRefs(expected.Css, actual.Css);
CompareContentCollectionRefs(expected.Images, actual.Images);
CompareContentCollectionRefs(expected.Fonts, actual.Fonts);
CompareContentCollectionRefs(expected.Audio, actual.Audio);
CompareContentCollectionRefs(expected.AllFiles, actual.AllFiles);
}

Expand Down
1 change: 1 addition & 0 deletions Source/VersOne.Epub.Test/Comparers/EpubMetadataComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public static void CompareEpubMetadataLinks(EpubMetadataLink expected, EpubMetad
Assert.Equal(expected.Properties, actual.Properties);
Assert.Equal(expected.Refines, actual.Refines);
Assert.Equal(expected.Relationships, actual.Relationships);
Assert.Equal(expected.HrefLanguage, actual.HrefLanguage);
}

public static void CompareEpubMetadataMetas(EpubMetadataMeta expected, EpubMetadataMeta actual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ private static IEnumerable<CustomType> CreateTypes()
{ nameof(EpubContent.Css), PropertyDefaultValue.EMPTY_OBJECT },
{ nameof(EpubContent.Images), PropertyDefaultValue.EMPTY_OBJECT },
{ nameof(EpubContent.Fonts), PropertyDefaultValue.EMPTY_OBJECT },
{ nameof(EpubContent.Audio), PropertyDefaultValue.EMPTY_OBJECT },
{ nameof(EpubContent.AllFiles), PropertyDefaultValue.EMPTY_OBJECT }
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,36 +90,36 @@
"$content": "epub://Content/chapter1-audio.mp3",
"FilePath": "Content/chapter1-audio.mp3",
"Key": "chapter1-audio.mp3",
"ContentType": "OTHER",
"ContentType": "AUDIO_MP3",
"ContentMimeType": "audio/mpeg"
},
{
"$id": 11,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/title.mp3",
"FilePath": "Content/title.mp3",
"Key": "title.mp3",
"ContentType": "AUDIO_MP3",
"ContentMimeType": "audio/mpeg"
},
{
"$id": 12,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/chapter2.xml",
"FilePath": "Content/chapter2.xml",
"Key": "chapter2.xml",
"ContentType": "OTHER",
"ContentMimeType": "text/example+xml"
},
{
"$id": 12,
"$id": 13,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/chapter3.xml",
"FilePath": "Content/chapter3.xml",
"Key": "chapter3.xml",
"ContentType": "OTHER",
"ContentMimeType": "application/z3998-auth+xml"
},
{
"$id": 13,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/title.mp3",
"FilePath": "Content/title.mp3",
"Key": "title.mp3",
"ContentType": "OTHER",
"ContentMimeType": "audio/mpeg"
},
{
"$id": 14,
"$type": "EpubLocalTextContentFile",
Expand Down Expand Up @@ -740,6 +740,16 @@
}
}
},
"Audio": {
"Local": {
"chapter1-audio.mp3": {
"$ref": 10
},
"title.mp3": {
"$ref": 11
}
}
},
"AllFiles": {
"Local": {
"front.html": {
Expand Down Expand Up @@ -772,13 +782,13 @@
"chapter1-audio.mp3": {
"$ref": 10
},
"chapter2.xml": {
"title.mp3": {
"$ref": 11
},
"chapter3.xml": {
"chapter2.xml": {
"$ref": 12
},
"title.mp3": {
"chapter3.xml": {
"$ref": 13
},
"toc.ncx": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,33 @@
},
{
"$id": 11,
"$type": "EpubLocalTextContentFile",
"$content": "epub://Content/chapter1.smil",
"FilePath": "Content/chapter1.smil",
"Key": "chapter1.smil",
"ContentType": "SMIL",
"ContentMimeType": "application/smil+xml"
},
{
"$id": 12,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/chapter1-audio.mp3",
"FilePath": "Content/chapter1-audio.mp3",
"Key": "chapter1-audio.mp3",
"ContentType": "OTHER",
"ContentType": "AUDIO_MP3",
"ContentMimeType": "audio/mpeg"
},
{
"$id": 12,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/title.mp3",
"FilePath": "Content/title.mp3",
"Key": "title.mp3",
"ContentType": "AUDIO_MP3",
"ContentMimeType": "audio/mpeg"
},
{
"$id": 13,
"$type": "EpubLocalTextContentFile",
"$content": "epub://Content/chapter1.smil",
"FilePath": "Content/chapter1.smil",
"Key": "chapter1.smil",
"ContentType": "SMIL",
"ContentMimeType": "application/smil+xml"
},
{
"$id": 14,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/chapter2.xml",
"FilePath": "Content/chapter2.xml",
Expand All @@ -121,23 +130,14 @@
"ContentMimeType": "text/example+xml"
},
{
"$id": 14,
"$id": 15,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/chapter3.xml",
"FilePath": "Content/chapter3.xml",
"Key": "chapter3.xml",
"ContentType": "OTHER",
"ContentMimeType": "application/z3998-auth+xml"
},
{
"$id": 15,
"$type": "EpubLocalByteContentFile",
"$content": "epub://Content/title.mp3",
"FilePath": "Content/title.mp3",
"Key": "title.mp3",
"ContentType": "OTHER",
"ContentMimeType": "audio/mpeg"
},
{
"$id": 16,
"$type": "EpubLocalByteContentFile",
Expand Down Expand Up @@ -386,7 +386,8 @@
"MediaType": "application/xhtml+xml",
"Relationships": [
"RECORD"
]
],
"HrefLanguage": null
},
{
"Href": "https://example.com/onix/123",
Expand All @@ -398,15 +399,17 @@
"Relationships": [
"RECORD",
"ONIX_RECORD"
]
],
"HrefLanguage": null
},
{
"Href": "book.atom",
"Id": "link-3",
"MediaType": "application/atom+xml;type=entry;profile=opds-catalog",
"Relationships": [
"RECORD"
]
],
"HrefLanguage": null
},
{
"Href": "title.mp3",
Expand All @@ -415,7 +418,8 @@
"Refines": "#title",
"Relationships": [
"VOICING"
]
],
"HrefLanguage": null
}
],
"MetaItems": [
Expand Down Expand Up @@ -988,6 +992,16 @@
}
}
},
"Audio": {
"Local": {
"chapter1-audio.mp3": {
"$ref": 11
},
"title.mp3": {
"$ref": 12
}
}
},
"AllFiles": {
"Local": {
"front.html": {
Expand Down Expand Up @@ -1020,19 +1034,19 @@
"font.ttf": {
"$ref": 10
},
"chapter1.smil": {
"chapter1-audio.mp3": {
"$ref": 11
},
"chapter1-audio.mp3": {
"title.mp3": {
"$ref": 12
},
"chapter2.xml": {
"chapter1.smil": {
"$ref": 13
},
"chapter3.xml": {
"chapter2.xml": {
"$ref": 14
},
"title.mp3": {
"chapter3.xml": {
"$ref": 15
},
"book.atom": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public class EpubNarrationPhraseTests
[Fact(DisplayName = "Constructing a EpubNarrationPhrase instance with non-null parameters should succeed")]
public void ConstructorWithNonNullParametersTest()
{
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, TEXT_CONTENT_ANCHOR, TestEpubContent.AudioFile, AudioContentBegin, AudioContentEnd);
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, TEXT_CONTENT_ANCHOR, TestEpubContent.Audio1File, AudioContentBegin, AudioContentEnd);
EpubContentComparer.CompareEpubLocalTextContentFiles(TestEpubContent.Chapter1File, epubNarrationPhrase.TextContentFile);
Assert.Equal(TEXT_CONTENT_ANCHOR, epubNarrationPhrase.TextContentAnchor);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.AudioFile, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.Audio1File, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubNarrationComparers.CompareEpubNarrationTimestamps(AudioContentBegin, epubNarrationPhrase.AudioContentBegin);
EpubNarrationComparers.CompareEpubNarrationTimestamps(AudioContentEnd, epubNarrationPhrase.AudioContentEnd);
}

[Fact(DisplayName = "Constructor should throw ArgumentNullException if textContentFile parameter is null")]
public void ConstructorWithNullTextContentFileTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubNarrationPhrase(null!, TEXT_CONTENT_ANCHOR, TestEpubContent.AudioFile, AudioContentBegin, AudioContentEnd));
Assert.Throws<ArgumentNullException>(() => new EpubNarrationPhrase(null!, TEXT_CONTENT_ANCHOR, TestEpubContent.Audio1File, AudioContentBegin, AudioContentEnd));
}

[Fact(DisplayName = "Constructing a EpubNarrationPhrase instance with null textContentAnchor parameter should succeed")]
public void ConstructorWithNullTextContentAnchorParameterTest()
{
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, null, TestEpubContent.AudioFile, AudioContentBegin, AudioContentEnd);
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, null, TestEpubContent.Audio1File, AudioContentBegin, AudioContentEnd);
EpubContentComparer.CompareEpubLocalTextContentFiles(TestEpubContent.Chapter1File, epubNarrationPhrase.TextContentFile);
Assert.Null(epubNarrationPhrase.TextContentAnchor);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.AudioFile, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.Audio1File, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubNarrationComparers.CompareEpubNarrationTimestamps(AudioContentBegin, epubNarrationPhrase.AudioContentBegin);
EpubNarrationComparers.CompareEpubNarrationTimestamps(AudioContentEnd, epubNarrationPhrase.AudioContentEnd);
}
Expand All @@ -52,21 +52,21 @@ public void ConstructorWithNullAudioContentFileParameterTest()
[Fact(DisplayName = "Constructing a EpubNarrationPhrase instance with null audioContentBegin parameter should succeed")]
public void ConstructorWithNullAudioContentBeginParameterTest()
{
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, TEXT_CONTENT_ANCHOR, TestEpubContent.AudioFile, null, AudioContentEnd);
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, TEXT_CONTENT_ANCHOR, TestEpubContent.Audio1File, null, AudioContentEnd);
EpubContentComparer.CompareEpubLocalTextContentFiles(TestEpubContent.Chapter1File, epubNarrationPhrase.TextContentFile);
Assert.Equal(TEXT_CONTENT_ANCHOR, epubNarrationPhrase.TextContentAnchor);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.AudioFile, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.Audio1File, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
Assert.Null(epubNarrationPhrase.AudioContentBegin);
EpubNarrationComparers.CompareEpubNarrationTimestamps(AudioContentEnd, epubNarrationPhrase.AudioContentEnd);
}

[Fact(DisplayName = "Constructing a EpubNarrationPhrase instance with null audioContentEnd parameter should succeed")]
public void ConstructorWithNullAudioContentEndParameterTest()
{
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, TEXT_CONTENT_ANCHOR, TestEpubContent.AudioFile, AudioContentBegin, null);
EpubNarrationPhrase epubNarrationPhrase = new(TestEpubContent.Chapter1File, TEXT_CONTENT_ANCHOR, TestEpubContent.Audio1File, AudioContentBegin, null);
EpubContentComparer.CompareEpubLocalTextContentFiles(TestEpubContent.Chapter1File, epubNarrationPhrase.TextContentFile);
Assert.Equal(TEXT_CONTENT_ANCHOR, epubNarrationPhrase.TextContentAnchor);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.AudioFile, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubContentComparer.CompareEpubLocalByteContentFiles(TestEpubContent.Audio1File, epubNarrationPhrase.AudioContentFile as EpubLocalByteContentFile);
EpubNarrationComparers.CompareEpubNarrationTimestamps(AudioContentBegin, epubNarrationPhrase.AudioContentBegin);
Assert.Null(epubNarrationPhrase.AudioContentEnd);
}
Expand Down
1 change: 1 addition & 0 deletions Source/VersOne.Epub.Test/Unit/Readers/BookReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ private static EpubReaderOptions CreateEpubReaderOptionsToDownloadRemoteFiles()
testContentDownloader.AddByteRemoteFile(REMOTE_FONT_CONTENT_FILE_HREF, TestEpubFiles.REMOTE_FONT_FILE_CONTENT);
testContentDownloader.AddTextRemoteFile(REMOTE_XML_CONTENT_FILE_HREF, TestEpubFiles.REMOTE_XML_FILE_CONTENT);
testContentDownloader.AddByteRemoteFile(REMOTE_AUDIO_CONTENT_FILE_HREF, TestEpubFiles.REMOTE_AUDIO_FILE_CONTENT);
testContentDownloader.AddByteRemoteFile(REMOTE_VIDEO_CONTENT_FILE_HREF, TestEpubFiles.REMOTE_VIDEO_FILE_CONTENT);
return new()
{
ContentDownloaderOptions = new ContentDownloaderOptions()
Expand Down
Loading

0 comments on commit 7c75acc

Please sign in to comment.