Skip to content

common

FileMetaHarvester

Bases: FileHarvester

Default harvester for basic common.file metadata.

Harvests file name, file size, mimetype and hashsum of the file.

Source code in src/metador_core/harvester/common.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class FileMetaHarvester(FileHarvester):
    """Default harvester for basic common.file metadata.

    Harvests file name, file size, mimetype and hashsum of the file.
    """

    class Plugin:
        name = "core.file.generic"
        version = (0, 1, 0)
        returns = schemas.PluginRef(name="core.file", version=(0, 1, 0))

    def run(self):
        path = self.args.filepath

        sz = path.stat().st_size
        hs = hashsum(open(path, "rb"), "sha256")
        mt = magic.from_file(path, mime=True)
        return self.schema(
            filename=path.name, contentSize=sz, sha256=hs, encodingFormat=mt
        )

ImageFileMetaHarvester

Bases: FileHarvester

Harvester to obtain dimensions (width and height) of an image file.

Source code in src/metador_core/harvester/common.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class ImageFileMetaHarvester(FileHarvester):
    """Harvester to obtain dimensions (width and height) of an image file."""

    class Plugin:
        name = "core.imagefile.dim"
        version = (0, 1, 0)
        returns = schemas.PluginRef(name="core.imagefile", version=(0, 1, 0))

    def run(self):
        path = self.args.filepath

        with Image.open(path) as img:
            width, height = img.size
        return self.schema(width=width, height=height)