chore: Remove python-magic dependency

It relies on the libmagic module which is not necessarily installed
everywhere. Most of the functionality that we need for our purposes can
be recreated with lighter-weight methods.
This commit is contained in:
Marty Oehme 2025-09-12 09:47:41 +02:00
parent 30bc8452fa
commit 7459fbeb0b
Signed by: Marty
GPG key ID: 4E535BC19C61886E
5 changed files with 33 additions and 12 deletions

View file

@ -1,10 +1,10 @@
# pyright: strict, reportMissingTypeStubs=false, reportUnknownMemberType=false
import mimetypes
from collections.abc import Generator
from pathlib import Path
from typing import NamedTuple, cast
import Levenshtein
import magic
import papis.config
import papis.logging
import pymupdf as mu
@ -77,7 +77,7 @@ class PdfExtractor:
def _is_pdf(self, fname: Path) -> bool:
"""Check if file is a pdf, using mime type."""
return magic.from_file(fname, mime=True) == "application/pdf"
return mimetypes.guess_type(fname)[0] == "application/pdf"
def _get_annotation_content(
self, page: mu.Page, annotation: mu.Annot