parseWithFallbackTitle method

  1. @override
Future<PubBox?> parseWithFallbackTitle(
  1. String fileAtPath,
  2. String fallbackTitle
)
override

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(
      publication: publication,
      path: file.canonicalPath,
      mediaType: MediaType.epub,
      drm: drm);
  container.rootFile.rootFilePath = await getRootFilePath(fetcher);

  return PubBox(publication, container);
}