Hello,
I think there is a problem when trying to read a CBZ file that has only one page/image.
This is my CBZ created by the library:
test.cbz
|_1.bmp # just 400x800 red image
|_ComicInfo.xml
I try this and i have an error:
>>> comic = ComicInfo.from_cbz('output/test.cbz')
Traceback (most recent call last):
File "c:\dev\test.py", line 50, in <module>
coco = ComicInfo.from_cbz('output/test.cbz')
File "C:\dev\.venv\lib\site-packages\cbz\comic.py", line 69, in from_cbz
return cls.__unpack_zip(path)
File "C:\dev\.venv\lib\site-packages\cbz\comic.py", line 166, in __unpack_zip
items=pages_info[i],
KeyError: 0
It tries to access the first element of the list, whereas in this case it's not a list but a dict.
When I have two images, no problem, the variable pages_info is a list.
The problem comes when you parse with xmldict: if there's only one occurrence, the parser returns the element but not a list of one element.
I've seen that there's a parameter in xmldict's parse method that allows you to force the result to be a list, regardless of the number of occurrences:
comic_info = xmltodict.parse(f.read(), force_list=('Pages')).get('ComicInfo', {})
I tested it myself and it seems to work.