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);
Fetcher? fetcher = await Fetcher.fromArchiveOrDirectory(fileAtPath);
if (fetcher == null) {
throw ContainerError.missingFile(fileAtPath);
}
Publication? publication =
(await _imageParser.parseFile(FileAsset(file), fetcher))
?.let((builder) {
LocalizedString title = LocalizedString.fromString(fallbackTitle);
Metadata metadata =
builder.manifest.metadata.copy(localizedTitle: title);
Manifest manifest = builder.manifest.copy(metadata: metadata);
return PublicationBuilder(
manifest: manifest,
fetcher: builder.fetcher,
servicesBuilder: builder.servicesBuilder);
})
.build()
.also((pub) {
pub.type = TYPE.cbz;
});
if (publication == null) {
return null;
}
PublicationContainer container = PublicationContainer(
path: file.canonicalPath, mediaType: MediaType.cbz);
return PubBox(publication, container);
}