standard-imghdr missing
Running under Linux Ubuntu, i am getting this error:
...
File "/media/shared/data/iLEAPP/scripts/artifacts/notes.py", line 7, in
After I added standard-imghdr in requirements.txt, everything is fine
BR, Jens
See #1246
Considering that and the code of imghdr up to Python 3.11 (see https://github.com/python/cpython/blob/3.11/Lib/imghdr.py ) I wonder if we could just replace line 151 of scripts/artifacts/notes.py by something else.
Both JPEG and PNG have relatively easy to identify file headers, son it's not too complicated, and we could drop the requirement (specially considering that imghdr has been deprecated).
the media functions in ilapfuncs are using a version of code to assess the mime type of a file.
see import: https://github.com/abrignoni/iLEAPP/blob/73698f2fb9aa0360a46cf3912fd281bc438b1193/scripts/ilapfuncs.py#L27
see usage: https://github.com/abrignoni/iLEAPP/blob/73698f2fb9aa0360a46cf3912fd281bc438b1193/scripts/ilapfuncs.py#L213
see code info: https://github.com/abrignoni/iLEAPP/blob/73698f2fb9aa0360a46cf3912fd281bc438b1193/scripts/filetype.py#L2-L5
@Johann-PLW added that code library when making the media check in functions. its a copy of code so there are no dependencies, although it is more complicated to update in this way. that said, the original repo doesnt seem to be getting much in the way of updates anyways. only issue i ran into with this code was that it could not identify an xml/svg mime type. the original repo has several comments about trying to resolve it, but repo owner hasnt been responsive.
I just checked the filetype project, and in general I like it. As for SVG, I found the author refers to this other project they built.
I'd say since we already have it in the project, we could use filetype and clean the dependency on imghdr. As an alternative, we could implement something like this:
def _is_jpg_or_png(path):
with open(path, "rb") as f:
header = f.read(32)
if (header[:3] == b"\xff\xd8\xff") or (header[:8] == b"\x89PNG\r\n\x1a\n"):
return True
return False
Which is basically what imghdr and filetype are do (each in their own way). In general I think we should use filetype as it is already part of our code.
In general I think we should use filetype as it is already part of our code.
Part of the code, but it also expands for future proofing or possible deficiency in existing code if attachments are allowed to be types other than jpg or png. Does notes do HEiC now that its default format for iphone camera?
Filetype returns a mime format, so image/jpeg type of value can be tested simply for 'image' starting the value. Big glaring hole now for xml-svg though lol.
edit: text formating