Trying to parse an epub file

Viewed 12

I am trying to parse epub files to extract all the text content from them for this I am using the epubx package. I am parsing the html using the html package. Here is the code that I am using to parse the data.

File _epubFile = File(file.path);
final contents = await _epubFile.readAsBytes();
EpubBookRef epub = await EpubReader.openBook(contents.toList());
var cont = await EpubReader.readTextContentFiles(epub.Content!.Html!);
List<String> htmlList = [];
for (var value in cont.values) {
    htmlList.add(value.Content!);
  }
var doc = parse(htmlList.join());
final String parsedString = parse(doc.body!.text).documentElement!.text;
return parsedString;

It working good and it's accurately extracts all the text from the epub files. But recently I came around few epubs where this code dosen't work at all. I tried debugging but I am not getting any clue although I have checked the code and the it works fine till here:

File _epubFile = File(file.path);
final contents = await _epubFile.readAsBytes();
EpubBookRef epub = await EpubReader.openBook(contents.toList());
var cont = await EpubReader.readTextContentFiles(epub.Content!.Html!);
List<String> htmlList = [];
for (var value in cont.values) {
     htmlList.add(value.Content!);
    }

If I print the html list using debugPrint(htmlList.join()); it returns me all the html within the epub file. But I am not able to parse it. It's working on many epubs but not working on some.

The link of the epub thats working here.

The link of the epub that is not working here

0 Answers
Related