Skip to content

load_editorial_package

LoadEditorialPackage

Bases: LoaderPlugin

Load editorial package to timeline.

Source code in client/ayon_hiero/plugins/load/load_editorial_package.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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)

remove(container)

Remove a container.

Source code in client/ayon_hiero/plugins/load/load_editorial_package.py
90
91
92
93
94
95
96
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)

update(container, context)

Update the container with the latest version.

Source code in client/ayon_hiero/plugins/load/load_editorial_package.py
79
80
81
82
83
84
85
86
87
88
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,
    )