Skip to content

The MagikaDetector class

The Magikattector is a deprectated Implementation of the abstract FormatDetector class and should not be used anymore. It will be removed in a later version.

gamslib.formatdetect.magikadetector.MagikaDetector

MagikaDetector()

Bases: FormatDetector

Detector that uses the Google Magika library to detect file formats.

Uses Magika's prediction engine to identify file types and MIME types. Applies corrections for known misclassifications (e.g., JSON-LD as JavaScript).

Initialize the MagikaDetector with Magika's BEST_GUESS prediction mode.

guess_file_type

guess_file_type(filepath)

Detect the format of a file using Magika and return a FormatInfo object.

PARAMETER DESCRIPTION
filepath

Path to the file to analyze.

TYPE: Path

RETURNS DESCRIPTION
FormatInfo

Object containing detected format information.

TYPE: FormatInfo

Notes
  • Applies corrections for known Magika misclassifications.
  • Uses DEFAULT_TYPE if Magika cannot determine the MIME type.
  • Integrates with xmltypes and jsontypes for subtype detection.

looks_like_xml staticmethod

looks_like_xml(filepath)

Return True if the file looks like an XML file.

has_xml_declaration staticmethod

has_xml_declaration(filepath)

Return True if filepath contains an xml declaration.