Skip to content

Commit

Permalink
EPUB: add "identifiers" to doc props (koreader#560)
Browse files Browse the repository at this point in the history
ie. "isbn:9783462312317", "asin:b0ckwvvv4z".
  • Loading branch information
baswag authored Apr 6, 2024
1 parent e6a5cc9 commit 5d2724b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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

0 comments on commit 5d2724b

Please sign in to comment.