From 81f3ff9f5bed7612c291cf23c6f3cb9317d8c6d5 Mon Sep 17 00:00:00 2001 From: Lionel Dricot Date: Sun, 6 Feb 2022 12:55:54 +0100 Subject: [PATCH] use magic by default if available to get mimetype --- offpunk.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/offpunk.py b/offpunk.py index 6971b6e..85285af 100755 --- a/offpunk.py +++ b/offpunk.py @@ -750,12 +750,13 @@ class GeminiItem(): path = self.path else: path = self._cache_path - mime,encoding = mimetypes.guess_type(path,strict=False) + if _HAS_MAGIC: + mime = magic.from_file(path,mime=True) + else: + mime,encoding = mimetypes.guess_type(path,strict=False) #gmi Mimetype is not recognized yet if not mime and path.endswith(".gmi"): mime = "text/gemini" - elif not mime and _HAS_MAGIC : - mime = magic.from_file(path,mime=True) elif not _HAS_MAGIC : print("Cannot guess the mime type of the file. Install Python-magic") if mime.startswith("text") and mime not in _FORMAT_RENDERERS: