Skip to content

timespan

Classes:

Attributes:

VTS_FRAMERATE module-attribute

VTS_FRAMERATE = vts_framerate

Region

Region(value: Any, framerate: Fraction, vts: int)

Bases: CustomEnum

Methods:

Attributes:

Source code in vssource/formats/dvd/parsedvd/timespan.py
51
52
53
54
def __init__(self, value: Any, framerate: Fraction, vts: int) -> None:
    self._value_ = value
    self.framerate = framerate
    self.vts = vts

NTSC class-attribute instance-attribute

NTSC = ('NTSC', Fraction(30000, 1001), 3)

PAL class-attribute instance-attribute

PAL = ('PAL', Fraction(25, 1), 1)

framerate instance-attribute

framerate = framerate

vts instance-attribute

vts = vts

from_framerate classmethod

from_framerate(framerate: float | Fraction) -> Region
Source code in vssource/formats/dvd/parsedvd/timespan.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@classmethod
def from_framerate(cls, framerate: float | Fraction) -> Region:
    key = Fraction(framerate)

    framerate_region_map = {r.framerate: r for r in Region}

    if framerate in framerate_region_map:
        return framerate_region_map[key]

    diffs = [(r, abs(float(key) - float(r.framerate))) for r in Region]

    diffs.sort(key=lambda x: x[1])

    return diffs[0][0]

from_param classmethod

from_param(value: Any, func_except: FuncExcept | None = None) -> Self

Return the enum value from a parameter.

Parameters:

  • value

    (Any) –

    Value to instantiate the enum class.

  • func_except

    (FuncExcept | None, default: None ) –

    Exception function.

Returns:

  • Self

    Enum value.

Raises:

Source code in jetpytools/enums/base.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@classmethod
def from_param(cls, value: Any, func_except: FuncExcept | None = None) -> Self:
    """
    Return the enum value from a parameter.

    Args:
        value: Value to instantiate the enum class.
        func_except: Exception function.

    Returns:
        Enum value.

    Raises:
        NotFoundEnumValue: Variable not found in the given enum.
    """
    func_except = func_except or cls.from_param

    try:
        return cls(value)
    except (ValueError, TypeError):
        pass

    if isinstance(func_except, tuple):
        func_name, var_name = func_except
    else:
        func_name, var_name = func_except, repr(cls)

    raise NotFoundEnumValueError(
        'The given value for "{var_name}" argument must be a valid {enum_name}, not "{value}"!\n'
        "Valid values are: [{readable_enum}].",
        func_name,
        var_name=var_name,
        enum_name=cls,
        value=value,
        readable_enum=(f"{name} ({value!r})" for name, value in cls.__members__.items()),
        reason=value,
    ) from None

vts_framerate classmethod

vts_framerate() -> Mapping[int, Fraction]
Source code in vssource/formats/dvd/parsedvd/timespan.py
71
72
73
74
@classproperty.cached
@classmethod
def vts_framerate(cls) -> Mapping[int, Fraction]:
    return {r.vts: r.framerate for r in Region}

TimeSpan dataclass

TimeSpan(hours: int, minutes: int, seconds: int, frames: int)

Methods:

Attributes:

Source code in vssource/formats/dvd/parsedvd/timespan.py
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(self, hours: int, minutes: int, seconds: int, frames: int):
    if ((frames >> 6) & 0x01) != 1:
        raise ValueError

    fps = frames >> 6

    if fps not in Region.vts_framerate:
        raise ValueError

    self.hour = hours
    self.minute = minutes
    self.second = seconds
    self.frame_u = frames

frame_u instance-attribute

frame_u: int = frames

hour instance-attribute

hour: int = hours

minute instance-attribute

minute: int = minutes

second instance-attribute

second: int = seconds

bcd_to_int staticmethod

bcd_to_int(bcd: int) -> int
Source code in vssource/formats/dvd/parsedvd/timespan.py
36
37
38
@staticmethod
def bcd_to_int(bcd: int) -> int:
    return ((0xFF & (bcd >> 4)) * 10) + (bcd & 0x0F)

get_seconds_float

get_seconds_float() -> float
Source code in vssource/formats/dvd/parsedvd/timespan.py
40
41
42
43
44
def get_seconds_float(self) -> float:
    # + frames / framerate
    return float(
        ((self.bcd_to_int(self.hour) * 60) + self.bcd_to_int(self.minute)) * 60 + self.bcd_to_int(self.second)
    )