diff --git a/src/book.cpp b/src/book.cpp index 5d1ff5e..bd1eba6 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -58,23 +58,34 @@ book read(const fs::path filepath, const bool raw) book current_book; current_book.language = [&filepath]() -> string { - pugi::xml_document xml; - auto opf_file_path{get_opf_file_path(filepath)}; - const std::string opf_file{ - zip::read_file(filepath, opf_file_path.string())}; - - const auto result{xml.load_buffer(&opf_file[0], opf_file.size())}; - if (result) + try { - auto lang{ - xml.child("package").child("metadata").child("dc:language")}; - if (lang == nullptr) + pugi::xml_document xml; + auto opf_file_path{get_opf_file_path(filepath)}; + const std::string opf_file{ + zip::read_file(filepath, opf_file_path.string())}; + + const auto result{xml.load_buffer(&opf_file[0], opf_file.size())}; + if (result) { - lang = xml.child("opf:package") - .child("opf:metadata") - .child("dc:language"); + auto lang{xml.child("package") + .child("metadata") + .child("dc:language")}; + if (lang == nullptr) + { + lang = xml.child("opf:package") + .child("opf:metadata") + .child("dc:language"); + } + return lang.text().as_string(); + } + } + catch (epubgrep::zip::exception &e) + { + if (e.code != 1) // 1 == container.xml not found. + { + LOG(log::sev::error) << e.what(); } - return lang.text().as_string(); } return ""; }();