Created
September 1, 2023 16:05
-
-
Save rgaudin/71a415332456dc85c8456bbbf4e124f7 to your computer and use it in GitHub Desktop.
Mini libzim tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DISTDIR=./libzim_dist | |
LIBDIR=$(DISTDIR)/lib | |
DYLD_LIBRARY_PATH=$(LIBDIR) | |
TARGET ?= macos-x86_64 | |
all: zimls | |
libzim_dist: | |
curl -L -O https://download.openzim.org/release/libzim/libzim_$(TARGET)-8.2.1-1.tar.gz \ | |
&& tar xf libzim_$(TARGET)-8.2.1-1.tar.gz \ | |
&& mv libzim_$(TARGET)-8.2.1-1 libzim_dist | |
zimls: zimls.cc libzim_dist | |
c++ -Wall -std=c++11 zimls.cc -o zimls -I$(DISTDIR)/include -L$(LIBDIR) -lzim | |
clean: | |
rm -f zimls | |
cleanall: clean | |
rm -rf ./libzim_dist | |
rm -rf ./test.zim | |
test.zim: | |
curl -L -o test.zim https://download.kiwix.org/zim/wikipedia/wikipedia_cr_all_nopic_2023-08.zim | |
test: zimls test.zim | |
DYLD_LIBRARY_PATH=$(DYLD_LIBRARY_PATH) ./zimls test.zim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zim/item.h> | |
#include <zim/archive.h> | |
void readzim(const std::string& originFilename) | |
{ | |
zim::Archive origin(originFilename); | |
std::cout << "UUID: " + std::string(origin.getUuid()) << std::endl; | |
std::cout << "Filename: " + origin.getFilename() << std::endl; | |
std::cout << "Filesize: " + std::to_string(origin.getFilesize()) << std::endl; | |
std::cout << "Nb. Entries (all): " + std::to_string(origin.getAllEntryCount()) << std::endl; | |
std::cout << "Nb. Entries: " + std::to_string(origin.getEntryCount()) << std::endl; | |
std::cout << "Nb. Articles: " + std::to_string(origin.getArticleCount()) << std::endl; | |
std::cout << "Nb. Media: " + std::to_string(origin.getMediaCount()) << std::endl; | |
auto fromNewNamespace = origin.hasNewNamespaceScheme(); | |
try { | |
auto mainPath = origin.getMainEntry().getItem(true).getPath(); | |
if (!fromNewNamespace) { | |
mainPath = mainPath.substr(2, std::string::npos); | |
std::cout << "mainPath: " + mainPath << std::endl; | |
} | |
} catch(...) {} | |
if (origin.hasChecksum()) { | |
auto checksum = origin.getChecksum(); | |
std::cout << "checksum: " + checksum << std::endl; | |
} | |
try { | |
auto illustrationSizes = origin.getIllustrationSizes(); | |
std::cout << "Illustrations: "; | |
if (!illustrationSizes.empty()) { | |
std::string sizesValue = ""; | |
std::for_each(illustrationSizes.cbegin(), illustrationSizes.cend(), [](unsigned int size) { | |
std::cout << size << "x" << size << " "; | |
}); | |
} else { | |
std::cout << "Illustrations: None"; | |
} | |
std::cout << std::endl; | |
} catch(...) {} | |
for(auto& metakey:origin.getMetadataKeys()) { | |
auto metadata = origin.getMetadata(metakey); | |
if (metakey == "Illustration_48x48@1") { | |
metadata = "PRESENT"; | |
} | |
std::cout << " " + metakey + ": " + metadata << std::endl; | |
} | |
std::cout << "--- Entries ---" << std::endl; | |
for(auto& entry:origin.iterEfficient()) { | |
std::string message = entry.getPath(); | |
if (fromNewNamespace) { | |
message += " (redirect to " + entry.getRedirectEntry().getPath() + ")"; | |
} | |
message += " -- " + entry.getTitle(); | |
std::cout << message << std::endl; | |
} | |
} | |
int main(int argc, char* argv[]) | |
{ | |
std::cout << "zimls" << std::endl;; | |
if(argc!=2) | |
{ | |
std::cout << std::endl << "Usage: " << argv[0] << " ZIM_PATH" << std::endl; | |
return -1; | |
} | |
std::string originFilename = argv[1]; | |
try | |
{ | |
readzim(originFilename); | |
} | |
catch (const std::exception& e) | |
{ | |
std::cerr << e.what() << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment