feat: Only activate pocketbook extractor optionally

Since we make the dependencies for pocketbook html extraction optional
as an extra, this commit ensures the extractor (and cli option) only
gets loaded when they exist.
This commit is contained in:
Marty Oehme 2024-01-24 12:07:04 +01:00
parent e1e09b6011
commit e7e5258b34
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -1,8 +1,19 @@
import papis.logging
from papis_extract.extraction import Extractor from papis_extract.extraction import Extractor
from papis_extract.extractors import pdf from papis_extract.extractors import pdf
from papis_extract.extractors.pocketbook import PocketBookExtractor from papis_extract.extractors.pocketbook import PocketBookExtractor
logger = papis.logging.get_logger(__name__)
all_extractors: dict[str, Extractor] = { all_extractors: dict[str, Extractor] = {
"pdf": pdf.PdfExtractor(), "pdf": pdf.PdfExtractor(),
"pocketbook": PocketBookExtractor(),
} }
try:
import bs4
import magic
all_extractors["pocketbook"] = PocketBookExtractor()
except ImportError:
logger.debug("pocketbook extractor not activated.")