forked from creatint/dart-epub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request creatint#1 from jarontai/jarontai
Merge from Jarontai
- Loading branch information
Showing
5 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import 'dart:io' as io; | ||
|
||
import 'package:path/path.dart' as path; | ||
import 'package:epub/epub.dart'; | ||
|
||
main(List<String> args) async { | ||
//Get the epub into memory somehow | ||
String fileName = "hittelOnGoldMines.epub"; | ||
String fullPath = path.join(io.Directory.current.path, 'test', fileName); | ||
var targetFile = new io.File(fullPath); | ||
List<int> bytes = await targetFile.readAsBytes(); | ||
|
||
// Opens a book and reads all of its content into the memory | ||
EpubBook epubBook = await EpubReader.readBook(bytes); | ||
|
||
// COMMON PROPERTIES | ||
|
||
// Book's title | ||
String title = epubBook.Title; | ||
|
||
// Book's authors (comma separated list) | ||
String author = epubBook.Author; | ||
|
||
// Book's authors (list of authors names) | ||
List<String> authors = epubBook.AuthorList; | ||
|
||
// Book's cover image (null if there is no cover) | ||
Image coverImage = epubBook.CoverImage; | ||
|
||
// CHAPTERS | ||
|
||
// Enumerating chapters | ||
epubBook.Chapters.forEach((EpubChapter chapter) { | ||
// Title of chapter | ||
String chapterTitle = chapter.Title; | ||
|
||
// HTML content of current chapter | ||
String chapterHtmlContent = chapter.HtmlContent; | ||
|
||
// Nested chapters | ||
List<EpubChapter> subChapters = chapter.SubChapters; | ||
}); | ||
|
||
// CONTENT | ||
|
||
// Book's content (HTML files, stlylesheets, images, fonts, etc.) | ||
EpubContent bookContent = epubBook.Content; | ||
|
||
// IMAGES | ||
|
||
// All images in the book (file name is the key) | ||
Map<String, EpubByteContentFile> images = bookContent.Images; | ||
|
||
EpubByteContentFile firstImage = images.isNotEmpty ? images.values.first : null; | ||
|
||
// Content type (e.g. EpubContentType.IMAGE_JPEG, EpubContentType.IMAGE_PNG) | ||
EpubContentType contentType = firstImage?.ContentType; | ||
|
||
// MIME type (e.g. "image/jpeg", "image/png") | ||
String mimeContentType = firstImage?.ContentMimeType; | ||
|
||
// HTML & CSS | ||
|
||
// All XHTML files in the book (file name is the key) | ||
Map<String, EpubTextContentFile> htmlFiles = bookContent.Html; | ||
|
||
// All CSS files in the book (file name is the key) | ||
Map<String, EpubTextContentFile> cssFiles = bookContent.Css; | ||
|
||
// Entire HTML content of the book | ||
htmlFiles.values.forEach((EpubTextContentFile htmlFile) { | ||
String htmlContent = htmlFile.Content; | ||
}); | ||
|
||
// All CSS content in the book | ||
cssFiles.values.forEach((EpubTextContentFile cssFile) { | ||
String cssContent = cssFile.Content; | ||
}); | ||
|
||
// OTHER CONTENT | ||
|
||
// All fonts in the book (file name is the key) | ||
Map<String, EpubByteContentFile> fonts = bookContent.Fonts; | ||
|
||
// All files in the book (including HTML, CSS, images, fonts, and other types of files) | ||
Map<String, EpubContentFile> allFiles = bookContent.AllFiles; | ||
|
||
// ACCESSING RAW SCHEMA INFORMATION | ||
|
||
// EPUB OPF data | ||
EpubPackage package = epubBook.Schema.Package; | ||
|
||
// Enumerating book's contributors | ||
package.Metadata.Contributors.forEach((contributor) { | ||
String contributorName = contributor.Contributor; | ||
String contributorRole = contributor.Role; | ||
}); | ||
|
||
// EPUB NCX data | ||
EpubNavigation navigation = epubBook.Schema.Navigation; | ||
|
||
// Enumerating NCX metadata | ||
navigation.Head.Metadata.forEach((meta) { | ||
String metadataItemName = meta.Name; | ||
String metadataItemContent = meta.Content; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ author: Colin Nelson <[email protected]> | |
description: Epub Parser for Dart | ||
homepage: https://github.com/orthros/dart-epub | ||
environment: | ||
sdk: '>=1.13.2 <2.0.0' | ||
sdk: ">=1.21.0 <2.0.0" | ||
dependencies: | ||
async: ^1.13.2 | ||
archive: ^1.0.28 | ||
xml: ^2.5.0 | ||
image: ^1.1.26 | ||
async: "^1.8.0" | ||
archive: "^1.0.33" | ||
xml: "^2.6.0" | ||
image: "^1.1.29" | ||
dev_dependencies: | ||
scheduled_test: '^0.12.0' | ||
test: '^0.12.7' | ||
path: any | ||
scheduled_test: "^0.12.0" | ||
test: "^0.12.0" | ||
path: "^1.5.1" |