parseWithFallbackTitle method
Parse a file and return a PubBox
instance if the format is supported by
the parser.
It has a fallbackTitle
if none is found in the publication.
Implementation
@override
Future<PubBox?> parseWithFallbackTitle(
String fileAtPath, String fallbackTitle) async {
File file = File(fileAtPath);
FileAsset asset = FileAsset(file);
Fetcher? fetcher = await Fetcher.fromArchiveOrDirectory(fileAtPath);
if (fetcher == null) {
throw ContainerError.missingFile(fileAtPath);
}
Drm? drm = (await fetcher.isProtectedWithLcp()) ? Drm.lcp : null;
PublicationBuilder? builder;
try {
builder = await _parse(asset, fetcher, fallbackTitle);
} on Exception {
return null;
}
if (builder == null) {
return null;
}
Publication publication = builder.build().also((pub) {
pub.type = TYPE.epub;
// This might need to be moved as it's not really about parsing the EPUB but it
// sets values needed (in UserSettings & ContentFilter)
pub.setLayoutStyle();
});
PublicationContainer container = PublicationContainer(
path: file.canonicalPath, mediaType: MediaType.epub, drm: drm);
container.rootFile.rootFilePath = await _getRootFilePath(fetcher);
return PubBox(publication, container);
}