Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPUB: add identifiers to doc props #560

Merged
merged 4 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions crengine/include/lvdocview.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ class LVDocView : public CacheLoadingCallback
lString32 getDescription() { return m_doc_props->getStringDef(DOC_PROP_DESCRIPTION); }
/// returns book keywords (separated by "; ")
lString32 getKeywords() { return m_doc_props->getStringDef(DOC_PROP_KEYWORDS); }
/// returns book identifiers (scheme:identifier separated by "\n")
lString32 getIdentifiers() { return m_doc_props->getStringDef(DOC_PROP_IDENTIFIERS); }
/// returns book series name and number (series name #1)
lString32 getSeries()
{
Expand Down
1 change: 1 addition & 0 deletions crengine/include/lvtinydom.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ extern const int gDOMVersionCurrent;
#define DOC_PROP_LANGUAGE "doc.language"
#define DOC_PROP_DESCRIPTION "doc.description"
#define DOC_PROP_KEYWORDS "doc.keywords"
#define DOC_PROP_IDENTIFIERS "doc.identifiers"
#define DOC_PROP_SERIES_NAME "doc.series.name"
#define DOC_PROP_SERIES_NUMBER "doc.series.number"
#define DOC_PROP_ARC_NAME "doc.archive.name"
Expand Down
30 changes: 30 additions & 0 deletions crengine/src/epubfmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,36 @@ bool ImportEpubDocument( LVStreamRef stream, ldomDocument * m_doc, LVDocViewCall
m_doc_props->setString(DOC_PROP_KEYWORDS, subjects);
CRLog::info("Authors: %s Title: %s", LCSTR(authors), LCSTR(title));

// Return possibly multiple <dc:identifier> (identifiers)
// as a single doc_props string with values in a key-value format (scheme:identifier) separated by ;
bool identifiers_set = false;
lString32 identifiers;
// Iterate all package/metadata/identifier
lUInt16 identifier_id = doc->getElementNameIndex(U"identifier");
for (size_t i=0; i<nb_metadata_items; i++) {
ldomNode * item = metadata->getChildNode(i);
if ( item->getNodeId() != identifier_id )
continue;
lString32 scheme = item->getAttributeValue(U"scheme");
lString32 identifier;
// In version 3, scheme is not set but the type is rather included in the text itself
if (scheme.empty()) {
identifier = item->getText().trim();
}
else {
// In version 2, the scheme is only found as attribute
identifier << scheme << ":" << item->getText().trim();
}
if (identifiers_set) {
identifiers << "\n" << identifier;
}
else {
identifiers << identifier;
identifiers_set = true;
}
}
m_doc_props->setString(DOC_PROP_IDENTIFIERS, identifiers);

bool hasSeriesMeta = false;
bool hasSeriesIdMeta = false;
// Iterate all package/metadata/meta
Expand Down