Ir para o conteúdo

Scene

Scene

Bases: BaseModel

Represents a unit of grouped asset references in a timeline.

title class-attribute instance-attribute

title: str | None = None

An optional title of the scene.

description class-attribute instance-attribute

description: str | None = None

An optional description of the scene.

asset_references class-attribute instance-attribute

asset_references: list[AssetReference] = Field(
    default_factory=list
)

A list of assets associated with the scene.

start_time property

start_time: float

The start time of the scene in seconds.

end_time property

end_time: float

The end time of the scene in seconds.

duration property

duration: float

The duration of the scene in seconds.

has_audio property

has_audio: bool

Check if the scene has an audio asset.

has_subtitles property

has_subtitles: bool

Check if the scene has a subtitle asset.

from_dict classmethod

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

Create a scene from a dictionary.

Parameters:

Name Type Description Default
data Mapping[str, Any]

The dictionary data.

required

Returns:

Type Description
Scene

The scene.

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

    :param data: The dictionary data.
    :return: The scene.
    """
    asset_refs = []

    for asset_ref in data.get("asset_references", []):
        if isinstance(asset_ref, Mapping):
            asset_ref = AssetReference.from_dict(asset_ref)
        asset_refs.append(asset_ref)

    return cls(
        title=data.get("title"),
        description=data.get("description"),
        asset_references=asset_refs,
    )

add_asset_references

add_asset_references(
    references: AssetReference | Sequence[AssetReference],
) -> Scene

Add asset references to the scene.

Parameters:

Name Type Description Default
references AssetReference | Sequence[AssetReference]

The asset references to add.

required

Returns:

Type Description
Scene

The scene.

Source code in src/mosaico/scene.py
def add_asset_references(self, references: AssetReference | Sequence[AssetReference]) -> Scene:
    """
    Add asset references to the scene.

    :param references: The asset references to add.
    :return: The scene.
    """
    references = references if isinstance(references, Sequence) else [references]
    self.asset_references.extend(references)
    return self

remove_references_by_asset_id

remove_references_by_asset_id(asset_id: str) -> Scene

Remove asset references by asset ID.

Parameters:

Name Type Description Default
asset_id str

The asset ID to remove.

required

Returns:

Type Description
Scene

The scene.

Source code in src/mosaico/scene.py
def remove_references_by_asset_id(self, asset_id: str) -> Scene:
    """
    Remove asset references by asset ID.

    :param asset_id: The asset ID to remove.
    :return: The scene.
    """
    self.asset_references = [ref for ref in self.asset_references if ref.asset_id != asset_id]
    return self

with_subtitle_params

with_subtitle_params(
    params: TextAssetParams | Mapping[str, Any]
) -> Scene

Add subtitle asset params to the scene.

Parameters:

Name Type Description Default
params TextAssetParams | Mapping[str, Any]

The subtitle asset params.

required

Returns:

Type Description
Scene

The scene.

Source code in src/mosaico/scene.py
def with_subtitle_params(self, params: TextAssetParams | Mapping[str, Any]) -> Scene:
    """
    Add subtitle asset params to the scene.

    :param params: The subtitle asset params.
    :return: The scene.
    """
    for ref in self.asset_references:
        if ref.asset_type == "subtitle":
            ref.asset_params = TextAssetParams.model_validate(params)
    return self