Transformers#

hircine supports modification of scraper results by the use of transformers. Transformers are functions that hook into the scraping process and may freely modify any Scraped Data before it is shown to the user.

A transformer is specified by decorating a generator function with the transformer() decorator.

@hircine.plugins.transformer#

Marks the decorated function as a transformer.

The decorated function must be a generator function that yields Scraped Data. The following parameters will be available to the decorated function:

Parameters:
  • generator – The scraper’s generator function.

  • info (ScraperInfo) – Information on the scraper.

class hircine.scraper.ScraperInfo(name, source, comic)#

A class containing informational data on a scraper.

Parameters:
  • name (str) – The name of the scraper.

  • source (str) – The data source, usually a well-defined name. For names used by built-in plugins, refer to the Scrapers reference.

  • comic (FullComic) – The comic being scraped.

Registering transformers#

To register transformers, place them into a module in the hircine.transformer entry point group. For example, put the following in a pyproject.toml file:

[project.entry-points.'hircine.transformer']
my_transformers = 'mytransformers.transformers'

Example#

from hircine.plugins import transformer
from hircine.scraper.types import Artist, Tag


@transformer
def transform(generator, info):
    for item in generator:
        # Ignore the "Drama" tag when scraping from mangadex
        if info.source == "mangadex":
            match item:
                case Tag(tag="Drama"):
                    continue

        # convert all Artist names to lowercase
        match item:
            case Artist(name):
                yield Artist(name.lower())
                continue

        # other items are not modified
        yield item