Skip to content

muxtools.main

Setup pydantic-model

Setup(episode: str = '01', config_path: str | Path | None = None, *, show_name: str = 'Example', clean_work_dirs: bool = False, out_dir: str = 'premux', out_name: str = '$show$ - $ep$ (premux)', mkv_title_naming: str = '$show$ - $ep$', debug: bool = True, error_on_danger: bool = False, work_dir: str | None = None, **options: Any)

Bases: MuxSettings

Something like an environment used for a lot of functions in this package. Mostly used for muxing and data locations (work directory and what not).

If you want to change any of the variables AFTER initialization make sure to use the Setup.edit function to do so. Read its docstring to get why.

Parameters:

Name Type Description Default
episode str

Episode identifier used for workdir and muxing

'01'
config_path str | Path | None

Optional explicit pyproject.toml or muxtools.toml path.

None
show_name str

The name of the show. Used for the $show$ placeholder in muxing.

'Example'
clean_work_dirs bool

Cleanup the work directories after muxing. Might be useful if you're muxing a ton of stuff.

False
out_dir str

The folder the muxed files will go into.

'premux'
out_name str

The naming template applied to the muxed files.

'$show$ - $ep$ (premux)'
mkv_title_naming str

The naming template applied to the mkv title.

'$show$ - $ep$'
work_dir str | None

In case you want to set a custom work directory for all the temp files.

None
debug bool

Enable or Disable various, possibly interesting, debug output of all functions in this package.

True
error_on_danger bool

Raise an error when normally a "danger" log would be printed.

False
Show JSON schema:
{
  "additionalProperties": true,
  "description": "Something like an environment used for a lot of functions in this package.\nMostly used for muxing and data locations (work directory and what not).\n\nIf you want to change any of the variables AFTER initialization make sure to use the `Setup.edit` function to do so.\nRead its docstring to get why.\n\n:param episode:                 Episode identifier used for workdir and muxing\n:param config_path:             Optional explicit pyproject.toml or muxtools.toml path.\n\n:param show_name:               The name of the show. Used for the $show$ placeholder in muxing.\n:param clean_work_dirs:         Cleanup the work directories after muxing. Might be useful if you're muxing a ton of stuff.\n:param out_dir:                 The folder the muxed files will go into.\n:param out_name:                The naming template applied to the muxed files.\n:param mkv_title_naming:        The naming template applied to the mkv title.\n:param work_dir:                In case you want to set a custom work directory for all the temp files.\n:param debug:                   Enable or Disable various, possibly interesting, debug output of all functions in this package.\n:param error_on_danger:         Raise an error when normally a \"danger\" log would be printed.",
  "properties": {
    "show_name": {
      "default": "Example",
      "title": "Show Name",
      "type": "string"
    },
    "clean_work_dirs": {
      "default": false,
      "title": "Clean Work Dirs",
      "type": "boolean"
    },
    "out_dir": {
      "default": "premux",
      "title": "Out Dir",
      "type": "string"
    },
    "out_name": {
      "default": "$show$ - $ep$ (premux)",
      "title": "Out Name",
      "type": "string"
    },
    "mkv_title_naming": {
      "default": "$show$ - $ep$",
      "title": "Mkv Title Naming",
      "type": "string"
    },
    "debug": {
      "default": true,
      "title": "Debug",
      "type": "boolean"
    },
    "error_on_danger": {
      "default": false,
      "title": "Error On Danger",
      "type": "boolean"
    },
    "episode": {
      "default": "01",
      "title": "Episode",
      "type": "string"
    },
    "config_path": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Config Path"
    },
    "work_dir": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Work Dir"
    }
  },
  "title": "Setup",
  "type": "object"
}

Config:

  • extra: allow
  • strict: True

Fields:

Source code in muxtools/main.py
def __init__(
    self,
    episode: str = "01",
    config_path: str | Path | None = None,
    **options: Any,
) -> None:
    unknown = options.keys() - MuxSettings.model_fields.keys() - {"work_dir"}
    if unknown:
        raise TypeError(f"Unknown Setup setting: {', '.join(sorted(unknown))}")
    path = Path(config_path) if config_path else None
    config = discover_config(explicit=path)
    project_values = config.settings.model_dump(exclude={"binaries"}) if config else {}
    overrides = {key: value for key, value in options.items() if value is not None}
    values: dict[str, Any] = {**project_values, **overrides, "episode": episode, "config_path": str(path) if path else None}
    super().__init__(**values)

    if not self.work_dir:
        self.work_dir = str(Path.cwd() / "_workdir" / self.episode)
    Path(self.work_dir).mkdir(parents=True, exist_ok=True)

    from .utils.env import save_setup

    save_setup(self)

edit

edit(attr: str, value: Any) -> Self

Sets a variable inside of Setup and saves it to the environment variables. You should use this to apply any changes because other functions will not make use of them otherwise!

Parameters:

Name Type Description Default
attr str

The name of the variable/attribute you want to change

required
value Any

The value this variable/attribute will have.

required
Source code in muxtools/main.py
def edit(self, attr: str, value: Any) -> Self:
    """
    Sets a variable inside of Setup and saves it to the environment variables.
    You should use this to apply any changes because other functions will not make use of them otherwise!

    :param attr:        The name of the variable/attribute you want to change
    :param value:       The value this variable/attribute will have.
    """
    setattr(self, attr, value)

    from .utils.env import save_setup

    save_setup(self)
    return self

set_default_sub_timesource

set_default_sub_timesource(timesource: Path | GlobSearch | str | float | list[int], timescale: TimeScale | int | None = None) -> Self

Set a default timesource and timescale for conversions in subtitle functions.

The source selection for this is a bit more limited than the explicit params in the respective functions due to certain types being hard to store in the environment.

Parameters:

Name Type Description Default
timesource Path | GlobSearch | str | float | list[int]

The source of timestamps/timecodes.

This can be a video file, a timestamps txt file, actual timestamps as integers, a muxtools VideoMeta json file or FPS as a fraction string or float.

required
timescale TimeScale | int | None

Unit of time (in seconds) in terms of which frame timestamps are represented.

For details check the docstring on the type.

None
Source code in muxtools/main.py
def set_default_sub_timesource(
    self,
    timesource: Path | GlobSearch | str | float | list[int],
    timescale: TimeScale | int | None = None,
) -> Self:
    """
    Set a default timesource and timescale for conversions in subtitle functions.

    The source selection for this is a bit more limited than the explicit params in the respective functions due to certain types being hard to store in the environment.

    :param timesource:          The source of timestamps/timecodes.\n
                                This can be a video file, a timestamps txt file, actual timestamps as integers,
                                a muxtools VideoMeta json file or FPS as a fraction string or float.
    :param timescale:           Unit of time (in seconds) in terms of which frame timestamps are represented.\n
                                For details check the docstring on the type.
    """
    if isinstance(timesource, GlobSearch):
        timesource = timesource.paths[0]

    if isinstance(timesource, Path):
        timesource = str(timesource.resolve())

    if isinstance(timescale, TimeScale):
        timescale = timescale.value

    self.edit("sub_timesource", timesource)
    return self.edit("sub_timescale", timescale)