do not try to render non-image files with chafa to avoid errors
This commit is contained in:
parent
ac80f537e2
commit
10ab7323bd
|
@ -4,6 +4,7 @@
|
||||||
- Making python-readability optional
|
- Making python-readability optional
|
||||||
- Removing "next" and "previous" which are quite confusing and not obvious
|
- Removing "next" and "previous" which are quite confusing and not obvious
|
||||||
- Fixing a crash when accessing an empty html page
|
- 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
|
## 1.3 - April 2th 2022
|
||||||
- Removed dependency to python-magic. File is now used directly (and should be on every system).
|
- Removed dependency to python-magic. File is now used directly (and should be on every system).
|
||||||
|
|
|
@ -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.
|
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
|
* [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.
|
* [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).
|
* 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).
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,11 @@ def inline_image(img_file,width):
|
||||||
#Chafa is faster than timg inline. Let use that one by default
|
#Chafa is faster than timg inline. Let use that one by default
|
||||||
inline = None
|
inline = None
|
||||||
ansi_img = ""
|
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_CHAFA:
|
||||||
if _HAS_PIL and not _NEW_CHAFA:
|
if _HAS_PIL and not _NEW_CHAFA:
|
||||||
# this code is a hack to remove frames from animated gif
|
# this code is a hack to remove frames from animated gif
|
||||||
|
|
Loading…
Reference in New Issue