Skip to content

Commit 3ccd403

Browse files
committed
Added Archive.media_count
1 parent c63ba11 commit 3ccd403

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `Archive.media_count`
13+
1014
### Changed
1115

1216
- Using libzim 8.1.0

libzim/libwrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class Archive : public Wrapper<zim::Archive>
158158
FORWARD(zim::size_type, getEntryCount)
159159
FORWARD(zim::size_type, getAllEntryCount)
160160
FORWARD(zim::size_type, getArticleCount)
161+
FORWARD(zim::size_type, getMediaCount)
161162
FORWARD(std::string, getChecksum)
162163
FORWARD(std::string, getFilename)
163164
FORWARD(bool, hasMainEntry)

libzim/libzim.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,13 @@ cdef class Archive:
987987
listing, resulting in this returning all entries."""
988988
return self.c_archive.getArticleCount()
989989

990+
@property
991+
def media_count(self) -> pyint:
992+
"""Number of media in the Archive
993+
994+
This definition of "media" is based on the mimetype."""
995+
return self.c_archive.getMediaCount()
996+
990997
def get_illustration_sizes(self) -> Set[pyint]:
991998
"""Sizes for which an illustration is available (@1 scale only)"""
992999
return self.c_archive.getIllustrationSizes()

libzim/zim.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ cdef extern from "libwrapper.h" namespace "wrapper":
156156
size_type getEntryCount() except +
157157
size_type getAllEntryCount() except +
158158
size_type getArticleCount() except +
159+
size_type getMediaCount() except +
159160

160161
string getChecksum() except +
161162
string getFilename() except +

tests/test_libzim_reader.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"entry_count": 0,
3535
"all_entry_count": 2,
3636
"article_count": 0,
37+
"media_count": 0,
3738
"suggestion_string": None,
3839
"suggestion_count": 0,
3940
"suggestion_result": [],
@@ -79,6 +80,7 @@
7980
"entry_count": 371,
8081
"all_entry_count": 371,
8182
"article_count": 129,
83+
"media_count": 45,
8284
"suggestion_string": "lucky",
8385
"suggestion_count": 1,
8486
"suggestion_result": ["A/That_Lucky_Old_Sun"],
@@ -122,6 +124,7 @@
122124
"entry_count": 60,
123125
"all_entry_count": 75,
124126
"article_count": 0,
127+
"media_count": 22,
125128
"suggestion_string": "Free",
126129
"suggestion_count": 1,
127130
"suggestion_result": [
@@ -176,6 +179,7 @@
176179
"entry_count": 19,
177180
"all_entry_count": 19,
178181
"article_count": 1,
182+
"media_count": 1,
179183
"suggestion_string": "empty",
180184
"suggestion_count": 1,
181185
"suggestion_result": ["A/empty.html"],
@@ -220,6 +224,7 @@
220224
"entry_count": 2,
221225
"all_entry_count": 16,
222226
"article_count": 1,
227+
"media_count": 1,
223228
"suggestion_string": None,
224229
"suggestion_count": None,
225230
"suggestion_result": None,
@@ -438,6 +443,7 @@ def test_reader_checksum(all_zims, filename, has_checksum, is_valid):
438443
"entry_count",
439444
"all_entry_count",
440445
"article_count",
446+
"media_count",
441447
"suggestion_string",
442448
"suggestion_count",
443449
"suggestion_result",
@@ -453,6 +459,7 @@ def test_reader_suggest_search(
453459
entry_count,
454460
all_entry_count,
455461
article_count,
462+
media_count,
456463
suggestion_string,
457464
suggestion_count,
458465
suggestion_result,
@@ -466,6 +473,7 @@ def test_reader_suggest_search(
466473
assert zim.entry_count == entry_count
467474
assert zim.all_entry_count == all_entry_count
468475
assert zim.article_count == article_count
476+
assert zim.media_count == media_count
469477

470478
if search_string is not None:
471479
query = Query().set_query(search_string)

0 commit comments

Comments
 (0)