Ir para o conteúdo

Asset Reference

AssetReference

Bases: BaseModel

Represents an asset used in a scene.

asset_id instance-attribute

asset_id: str

The ID of the asset.

asset_type instance-attribute

asset_type: AssetType

The refered asset type.

asset_params class-attribute instance-attribute

asset_params: AssetParams | None = None

The asset reference params.

start_time class-attribute instance-attribute

start_time: NonNegativeFloat = 0

The start time of the asset in seconds.

end_time class-attribute instance-attribute

end_time: NonNegativeFloat = 0

The end time of the asset in seconds.

effects class-attribute instance-attribute

effects: list[VideoEffect] = Field(default_factory=list)

The effects to apply to the asset.

duration property

duration: float

The duration of the asset in seconds.

from_asset classmethod

from_asset(
    asset: Asset,
    *,
    asset_params: AssetParams | None = None,
    start_time: float | None = None,
    end_time: float | None = None,
    effects: Sequence[VideoEffect] | None = None
) -> AssetReference

Create an asset reference from an asset.

Parameters:

Name Type Description Default
asset Asset

The asset to reference.

required
asset_params AssetParams | None

The asset params.

None
start_time float | None

The start time of the asset in seconds.

None
end_time float | None

The end time of the asset in seconds.

None

Returns:

Type Description
AssetReference

The asset reference.

Source code in src/mosaico/assets/reference.py
@classmethod
def from_asset(
    cls,
    asset: Asset,
    *,
    asset_params: AssetParams | None = None,
    start_time: float | None = None,
    end_time: float | None = None,
    effects: Sequence[VideoEffect] | None = None,
) -> AssetReference:
    """
    Create an asset reference from an asset.

    :param asset: The asset to reference.
    :param asset_params: The asset params.
    :param start_time: The start time of the asset in seconds.
    :param end_time: The end time of the asset in seconds.
    :return: The asset reference.
    """
    return cls(
        asset_id=asset.id,
        asset_type=asset.type,
        asset_params=asset_params or asset.params,
        start_time=start_time if start_time is not None else 0,
        end_time=end_time if end_time is not None else 0,
        effects=list(effects) if effects is not None else [],
    )

from_dict classmethod

from_dict(data: Mapping[str, Any]) -> AssetReference

Create an asset reference from a dictionary.

Parameters:

Name Type Description Default
data Mapping[str, Any]

The dictionary data.

required

Returns:

Type Description
AssetReference

The asset reference.

Source code in src/mosaico/assets/reference.py
@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> AssetReference:
    """
    Create an asset reference from a dictionary.

    :param data: The dictionary data.
    :return: The asset reference.
    """
    if "asset_type" not in data:
        msg = "Missing 'asset_type' key in asset reference data."
        raise ValueError(msg)

    if "asset_params" in data:
        params_cls = get_asset_params_class(data["asset_type"])
        data["asset_params"] = params_cls.model_validate(data["asset_params"])

    return cls.model_validate(data)

with_params

with_params(params: AssetParams) -> AssetReference

Add scene params to the asset reference.

Parameters:

Name Type Description Default
params AssetParams

The scene params to add.

required

Returns:

Type Description
AssetReference

The asset reference.

Source code in src/mosaico/assets/reference.py
def with_params(self, params: AssetParams) -> AssetReference:
    """
    Add scene params to the asset reference.

    :param params: The scene params to add.
    :return: The asset reference.
    """
    self.asset_params = params
    return self

with_start_time

with_start_time(start_time: float) -> AssetReference

Add a start time to the asset reference.

Parameters:

Name Type Description Default
start_time float

The start time to add.

required

Returns:

Type Description
AssetReference

The asset reference.

Source code in src/mosaico/assets/reference.py
def with_start_time(self, start_time: float) -> AssetReference:
    """
    Add a start time to the asset reference.

    :param start_time: The start time to add.
    :return: The asset reference.
    """
    self.start_time = start_time
    return self

with_end_time

with_end_time(end_time: float) -> AssetReference

Add an end time to the asset reference.

Parameters:

Name Type Description Default
end_time float

The end time to add.

required

Returns:

Type Description
AssetReference

The asset reference.

Source code in src/mosaico/assets/reference.py
def with_end_time(self, end_time: float) -> AssetReference:
    """
    Add an end time to the asset reference.

    :param end_time: The end time to add.
    :return: The asset reference.
    """
    self.end_time = end_time
    return self

with_effects

with_effects(effects: Sequence[Effect]) -> AssetReference

Add effects to the asset reference.

Parameters:

Name Type Description Default
effects Sequence[Effect]

The effects to add.

required

Returns:

Type Description
AssetReference

The asset reference.

Source code in src/mosaico/assets/reference.py
def with_effects(self, effects: Sequence[Effect]) -> AssetReference:
    """
    Add effects to the asset reference.

    :param effects: The effects to add.
    :return: The asset reference.
    """
    effects = cast(list[VideoEffect], effects)
    self.effects.extend(effects)
    return self