class LoadEditorialPackage(load.LoaderPlugin):
"""Load editorial package to timeline.
"""
product_types = {"editorial_pkg"}
representations = {"*"}
extensions = {"otio"}
label = "Load as Timeline"
order = -10
icon = "ei.align-left"
color = "orange"
@classmethod
def _get_container_data(
cls,
context: Dict[str, Any],
seq: hiero.core.Sequence
) -> Dict[str, str]:
return {
"schema": "ayon:container-3.0",
"id": AYON_CONTAINER_ID,
"loader": str(cls.__name__),
"representation": context["representation"]["id"],
"name": seq.guid(),
"namespace": seq.name(),
"objectName": seq.name(),
}
@classmethod
def _get_tag_name(cls, seq_guid: str) -> str:
return f"{seq_guid}_loaded_editpkg"
def load(self, context, name, namespace, data):
files = get_representation_path(context["representation"])
seq_bin = lib.create_bin(f"/{name}")
# Load clip
dirname = os.path.dirname(files)
media_paths = glob.glob(Path(dirname,"*.mov").as_posix())
conf_media_path = Path(media_paths[0]).as_posix()
seq_bin.createClip(conf_media_path)
# Load sequence from otio
seq = seq_bin.importSequence(files)
# Remap all clip to loaded clip
# (for some reasons, Hiero does not link the media properly)
for track in seq.items():
for track_item in track.items():
track_item.replaceClips(conf_media_path)
# Set Tag for loaded instance
edpkg_tag = tags.get_or_create_workfile_tag(
self._get_tag_name(seq.guid()),
create=True
)
tag_data = {
"metadata": self._get_container_data(context, seq),
"note": "AYON editorial pkg data",
}
tags.update_tag(edpkg_tag, tag_data)
def update(self, container, context):
"""Update the container with the latest version."""
product_name = context["product"]["name"]
self.remove(container)
self.load(
context,
product_name,
container["namespace"],
container,
)
def remove(self, container):
"""Remove a container."""
# TODO: remove the underlying sequence as well ?
# might need a confirmation before that.
seq_guid = container["name"]
tag_name = self._get_tag_name(seq_guid)
tags.remove_workfile_tag(tag_name)