aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/postprocessor/__init__.py
blob: faa4d6c9c2f593cdb2fe71fb24a9374b084bec3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-

# Copyright 2018-2020 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

"""Post-processing modules"""

import importlib

modules = [
    "classify",
    "compare",
    "exec",
    "metadata",
    "mtime",
    "ugoira",
    "zip",
]


def find(name):
    """Return a postprocessor class with the given name"""
    try:
        return _cache[name]
    except KeyError:
        pass

    klass = None
    if name in modules:  # prevent unwanted imports
        try:
            module = importlib.import_module("." + name, __package__)
        except ImportError:
            pass
        else:
            klass = module.__postprocessor__
    _cache[name] = klass
    return klass


# --------------------------------------------------------------------
# internals

_cache = {}