Skip to content

base

Classes:

PropEnumT module-attribute

PropEnumT = TypeVar('PropEnumT', bound=PropEnum)

PropEnum

Bases: CustomIntEnum

Methods:

  • apply

    Applies the property to the VideoNode.

  • ensure_presence

    Ensure the presence of the property in the VideoNode.

  • ensure_presences

    Ensure the presence of multiple PropEnums at once.

  • from_param_or_video

    Get the enum member from a value that can be casted to this prop value

  • from_res

    Get an enum member from the video resolution with heuristics.

  • from_video

    Get an enum member from the frame properties or optionally fall back to resolution when strict=False.

  • is_unknown

    Whether the value represents an unknown value.

  • is_valid

    Check if the given value is a valid int value of this enum.

  • prop_key

    The key used in props to store the enum.

Attributes:

  • pretty_string (str) –

    Get a pretty, displayable string of the enum member.

  • string (str) –

    Get the string representation used in resize plugin/encoders.

pretty_string property

pretty_string: str

Get a pretty, displayable string of the enum member.

string property

string: str

Get the string representation used in resize plugin/encoders.

apply

apply(clip: VideoNodeT) -> VideoNodeT

Applies the property to the VideoNode.

Source code in vstools/enums/base.py
105
106
107
108
109
110
def apply(self, clip: VideoNodeT) -> VideoNodeT:
    """
    Applies the property to the VideoNode.
    """

    return vs.core.std.SetFrameProp(clip, self.prop_key, self.value)

ensure_presence classmethod

ensure_presence(
    clip: VideoNodeT,
    value: int | Self | None,
    /,
    func: FuncExcept | None = None,
) -> VideoNodeT

Ensure the presence of the property in the VideoNode.

Source code in vstools/enums/base.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@classmethod
def ensure_presence(
    cls, clip: VideoNodeT, value: int | Self | None, /, func: FuncExcept | None = None
) -> VideoNodeT:
    """
    Ensure the presence of the property in the VideoNode.
    """

    enum_value = cls.from_param_or_video(value, clip, True, func)

    return vs.core.std.SetFrameProp(clip, enum_value.prop_key, enum_value.value)

ensure_presences staticmethod

ensure_presences(
    clip: VideoNodeT,
    prop_enums: Iterable[type[PropEnum] | PropEnum],
    func: FuncExcept | None = None,
) -> VideoNodeT

Ensure the presence of multiple PropEnums at once.

Source code in vstools/enums/base.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@staticmethod
def ensure_presences(
    clip: VideoNodeT, prop_enums: Iterable[type[PropEnum] | PropEnum], func: FuncExcept | None = None
) -> VideoNodeT:
    """
    Ensure the presence of multiple PropEnums at once.
    """

    return vs.core.std.SetFrameProps(
        clip,
        **{
            value.prop_key: value.value
            for value in (
                prop_enum if isinstance(prop_enum, PropEnum) else prop_enum.from_video(clip, True, func)
                for prop_enum in prop_enums
            )
        },
    )

from_param_or_video classmethod

from_param_or_video(
    value: Any,
    src: VideoNode | VideoFrame | FrameProps,
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self

Get the enum member from a value that can be casted to this prop value or grab it from frame properties.

If strict=False, gather the heuristics using the clip's size or format.

Parameters:

  • value

    (Any) –

    Value to cast.

  • src

    (VideoNode | VideoFrame | FrameProps) –

    Clip to get prop from.

  • strict

    (bool, default: False ) –

    Be strict about the frame properties. Default: False.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Source code in vstools/enums/base.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@classmethod
def from_param_or_video(
    cls,
    value: Any,
    src: vs.VideoNode | vs.VideoFrame | vs.FrameProps,
    strict: bool = False,
    func_except: FuncExcept | None = None,
) -> Self:
    """
    Get the enum member from a value that can be casted to this prop value
    or grab it from frame properties.

    If `strict=False`, gather the heuristics using the clip's size or format.

    Args:
        value: Value to cast.
        src: Clip to get prop from.
        strict: Be strict about the frame properties. Default: False.
        func_except: Function returned for custom error handling.
    """
    value = cls.from_param(value, func_except)

    if value is not None:
        return value

    return cls.from_video(src, strict, func_except)

from_res classmethod

from_res(frame: VideoNode | VideoFrame) -> Self

Get an enum member from the video resolution with heuristics.

Source code in vstools/enums/base.py
48
49
50
51
52
53
54
@classmethod
def from_res(cls, frame: vs.VideoNode | vs.VideoFrame) -> Self:
    """
    Get an enum member from the video resolution with heuristics.
    """

    raise NotImplementedError

from_video classmethod

from_video(
    src: VideoNode | VideoFrame | FrameProps,
    strict: bool = False,
    func: FuncExcept | None = None,
) -> Self

Get an enum member from the frame properties or optionally fall back to resolution when strict=False.

Source code in vstools/enums/base.py
56
57
58
59
60
61
62
63
64
@classmethod
def from_video(
    cls, src: vs.VideoNode | vs.VideoFrame | vs.FrameProps, strict: bool = False, func: FuncExcept | None = None
) -> Self:
    """
    Get an enum member from the frame properties or optionally fall back to resolution when strict=False.
    """

    raise NotImplementedError

is_unknown classmethod

is_unknown(value: int | Self) -> bool

Whether the value represents an unknown value.

Source code in vstools/enums/base.py
21
22
23
24
25
26
27
@classmethod
def is_unknown(cls, value: int | Self) -> bool:
    """
    Whether the value represents an unknown value.
    """

    return False

is_valid classmethod

is_valid(value: int) -> bool

Check if the given value is a valid int value of this enum.

Source code in vstools/enums/base.py
148
149
150
151
152
153
@classmethod
def is_valid(cls, value: int) -> bool:
    """
    Check if the given value is a valid int value of this enum.
    """
    return int(value) in map(int, cls.__members__.values())

prop_key classmethod

prop_key() -> str

The key used in props to store the enum.

Source code in vstools/enums/base.py
29
30
31
32
33
34
35
36
@classproperty
@classmethod
def prop_key(cls) -> str:
    """
    The key used in props to store the enum.
    """

    return f"_{cls.__name__}"