Improving MIME type detection for some common file types when they are missing from the system MIME database

Also allow the user to specify their own database via mime.types in the
kitty config directory. See #3056
This commit is contained in:
Kovid Goyal
2020-10-25 13:42:11 +05:30
parent e160cbf32b
commit 75a94bcd96
7 changed files with 62 additions and 13 deletions
+3 -6
View File
@@ -17,6 +17,7 @@ from .config import KeyAction, parse_key_action
from .constants import config_dir
from .typing import MatchType
from .utils import expandvars, log_error
from .guess_mime_type import guess_type
class MatchCriteria(NamedTuple):
@@ -75,12 +76,8 @@ def url_matches_criterion(purl: 'ParseResult', url: str, unquoted_path: str, mc:
if mc.type == 'mime':
import fnmatch
from mimetypes import guess_type
try:
mt = guess_type(unquoted_path)[0]
except Exception:
return False
if mt is None:
mt = guess_type(unquoted_path)
if not mt:
return False
mt = mt.lower()
for mpat in mc.value.split(','):