File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ void Book::update(const zim::Archive& archive) {
83
83
m_flavour = getMetaFlavour (archive);
84
84
m_tags = getMetaTags (archive);
85
85
m_category = getCategoryFromTags ();
86
- m_articleCount = archive. getArticleCount ( );
86
+ m_articleCount = getArchiveArticleCount (archive );
87
87
m_mediaCount = getArchiveMediaCount (archive);
88
88
m_size = static_cast <uint64_t >(getArchiveFileSize (archive)) << 10 ;
89
89
Original file line number Diff line number Diff line change @@ -125,6 +125,30 @@ unsigned int getArchiveMediaCount(const zim::Archive& archive) {
125
125
return counter;
126
126
}
127
127
128
+ unsigned int getArchiveArticleCount (const zim::Archive& archive) {
129
+ // [HACK]
130
+ // getArticleCount() returns different things depending of the "version" of the zim.
131
+ // On old zim (<=6), it returns the number of entry in `A` namespace
132
+ // On recent zim (>=7), it returns:
133
+ // - the number of entry in `C` namespace (==getEntryCount) if no frontArticleIndex is present
134
+ // - the number of front article if a frontArticleIndex is present
135
+ // The use case >=7 without frontArticleIndex is pretty rare so we don't care
136
+ // We can detect if we are reading a zim <= 6 by checking if we have a newNamespaceScheme.
137
+ if (archive.hasNewNamespaceScheme ()) {
138
+ // The articleCount is "good"
139
+ return archive.getArticleCount ();
140
+ } else {
141
+ // We have to parse the `M/Counter` metadata
142
+ unsigned int counter = 0 ;
143
+ for (const auto & pair:parseArchiveCounter (archive)) {
144
+ if (startsWith (pair.first , " text/html" )) {
145
+ counter += pair.second ;
146
+ }
147
+ }
148
+ return counter;
149
+ }
150
+ }
151
+
128
152
unsigned int getArchiveFileSize (const zim::Archive& archive) {
129
153
return archive.getFilesize () / 1024 ;
130
154
}
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ namespace kiwix
46
46
std::string& content, std::string& mimeType);
47
47
48
48
unsigned int getArchiveMediaCount (const zim::Archive& archive);
49
+ unsigned int getArchiveArticleCount (const zim::Archive& archive);
49
50
unsigned int getArchiveFileSize (const zim::Archive& archive);
50
51
51
52
zim::Item getFinalItem (const zim::Archive& archive, const zim::Entry& entry);
You can’t perform that action at this time.
0 commit comments