diff --git a/CHANGELOG b/CHANGELOG index 5bc23aa..2ad54d1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - Making python-readability optional - Removing "next" and "previous" which are quite confusing and not obvious - Fixing a crash when accessing an empty html page +- Not trying to display non-image files to avoid errors. (this requires "file") ## 1.3 - April 2th 2022 - Removed dependency to python-magic. File is now used directly (and should be on every system). diff --git a/README.md b/README.md index a981fa2..a7e342b 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,9 @@ To avoid using unstable or too recent libraries, the rule of thumb is that a lib Run command `version` in offpunk to see if you are missing some dependencies. -Highly recommended (packagers should probably make those mandatory): +Mandatory or highly recommended (packagers should probably make those mandatory): * [less](http://www.greenwoodsoftware.com/less/): mandatory but is probably already on your system -* [file](https://www.darwinsys.com/file/) is used to get the MIME type of cached objects. Should already be on your system. +* [file](https://www.darwinsys.com/file/) is used to get the MIME type of cached objects. Should already be on your system and may become mandatory. * [xdg-utils](https://www.freedesktop.org/wiki/Software/xdg-utils/) provides xdg-open which is highly recommended to open files without a renderer or a handler. It is also used for mailto: command. * The [cryptography library](https://pypi.org/project/cryptography/) will provide a better and slightly more secure experience when using the default TOFU certificate validation mode and is highly recommended (apt-get install python3-cryptography). diff --git a/offpunk.py b/offpunk.py index 72a0336..a0064f3 100755 --- a/offpunk.py +++ b/offpunk.py @@ -105,6 +105,11 @@ def inline_image(img_file,width): #Chafa is faster than timg inline. Let use that one by default inline = None ansi_img = "" + #We avoid errors by not trying to render non-image files + if shutil.which("file"): + mime = run("file -b --mime-type \"%s\""%img_file).strip() + if not "image" in mime: + return ansi_img if _HAS_CHAFA: if _HAS_PIL and not _NEW_CHAFA: # this code is a hack to remove frames from animated gif