openzim / python-libzim

Libzim binding for Python: read/write ZIM files in Python
https://pypi.org/project/libzim/
GNU General Public License v3.0
62 stars 22 forks source link

Can't set LongDescription #161

Closed rgaudin closed 1 year ago

rgaudin commented 1 year ago

Due to the use of pascalize in add_metadata, it is not possible to set any metadata with a name that does not obey this convention.

Given the spec doesn't mention any such requirement, and given libzim itself doesn't mangle with metadata names, I propose to simply remove it.

https://github.com/openzim/python-libzim/blob/12f82b4ec836b502311353ed25bfab687f571d4c/libzim/libzim.pyx#L550-L554

from libzim.writer import Creator

with Creator("test-pacalize.zim") as creator:
    creator.add_metadata("description", "HOP HOP")
    creator.add_metadata("LongDescription", "HOP HOP HOP")

from libzim.reader import Archive

zim = Archive("test-pacalize.zim")

zim.get_metadata("Description")
# b'HOP HOP'

zim.get_metadata("LongDescription")
---------------------------------------------------------------------------
# RuntimeError: Cannot find metadata

zim.get_metadata("Longdescription")
# b'HOP HOP HOP'
rgaudin commented 1 year ago

To be more precise, it is possible to set it by using add_metadata("long_description") but it forces user to use a specific format for no valid reason