From 127eb01138764e9e2d73e7ddda3044adcb0e1055 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 23 Dec 2020 17:57:35 +0100 Subject: [PATCH] resolve: swap family with families --- pype/hosts/resolve/plugin.py | 3 +- .../publish/collect_otio_frame_ranges.py | 2 +- .../publish/collect_otio_subset_resources.py | 109 +++++++++++++++--- 3 files changed, 95 insertions(+), 19 deletions(-) diff --git a/pype/hosts/resolve/plugin.py b/pype/hosts/resolve/plugin.py index 2616491652..fa4559efac 100644 --- a/pype/hosts/resolve/plugin.py +++ b/pype/hosts/resolve/plugin.py @@ -636,7 +636,8 @@ class PublishClip: "parents": self.parents, "hierarchyData": hierarchy_formating_data, "subset": self.subset, - "families": [self.subset_family] + "family": self.subset_family, + "families": ["clip"] } def _convert_to_entity(self, key): diff --git a/pype/plugins/global/publish/collect_otio_frame_ranges.py b/pype/plugins/global/publish/collect_otio_frame_ranges.py index 248158a1f4..d82c00412d 100644 --- a/pype/plugins/global/publish/collect_otio_frame_ranges.py +++ b/pype/plugins/global/publish/collect_otio_frame_ranges.py @@ -19,7 +19,7 @@ class CollectOcioFrameRanges(pyblish.api.InstancePlugin): label = "Collect OTIO Frame Ranges" order = pyblish.api.CollectorOrder - 0.58 - families = ["clip", "shot"] + families = ["shot"] hosts = ["resolve"] def process(self, instance): diff --git a/pype/plugins/global/publish/collect_otio_subset_resources.py b/pype/plugins/global/publish/collect_otio_subset_resources.py index 019b9f902f..e207885bb8 100644 --- a/pype/plugins/global/publish/collect_otio_subset_resources.py +++ b/pype/plugins/global/publish/collect_otio_subset_resources.py @@ -3,13 +3,10 @@ Requires: instance -> otio_clip -Optional: - instance -> review - Provides: instance -> otioReviewClips """ - +import os import clique import opentimelineio as otio import pyblish.api @@ -25,6 +22,9 @@ class CollectOcioSubsetResources(pyblish.api.InstancePlugin): hosts = ["resolve"] def process(self, instance): + if not instance.data.get("representations"): + instance.data["representations"] = list() + # get basic variables otio_clip = instance.data["otioClip"] @@ -36,6 +36,26 @@ class CollectOcioSubsetResources(pyblish.api.InstancePlugin): trimmed_media_range = pype.lib.trim_media_range( otio_avalable_range, otio_src_range_handles) + a_frame_start, a_frame_end = pype.lib.otio_range_to_frame_range( + otio_avalable_range) + + frame_start, frame_end = pype.lib.otio_range_to_frame_range( + trimmed_media_range) + + # fix frame_start and frame_end frame to be in range of + if frame_start < a_frame_start: + frame_start = a_frame_start + + if frame_end > a_frame_end: + frame_end = a_frame_end + + instance.data.update({ + "frameStart": frame_start, + "frameEnd": frame_end + }) + + self.log.debug( + "_ otio_avalable_range: {}".format(otio_avalable_range)) self.log.debug( "_ trimmed_media_range: {}".format(trimmed_media_range)) @@ -53,16 +73,13 @@ class CollectOcioSubsetResources(pyblish.api.InstancePlugin): if metadata.get("padding"): is_sequence = True - first, last = pype.lib.otio_range_to_frame_range( - trimmed_media_range) - self.log.info( - "first-last: {}-{}".format(first, last)) + "frame_start-frame_end: {}-{}".format(frame_start, frame_end)) if is_sequence: # file sequence way if hasattr(media_ref, "target_url_base"): - dirname = media_ref.target_url_base + self.staging_dir = media_ref.target_url_base head = media_ref.name_prefix tail = media_ref.name_suffix collection = clique.Collection( @@ -71,19 +88,77 @@ class CollectOcioSubsetResources(pyblish.api.InstancePlugin): padding=media_ref.frame_zero_padding ) collection.indexes.update( - [i for i in range(first, (last + 1))]) - # TODO: add representation - self.log.debug((dirname, collection)) + [i for i in range(frame_start, (frame_end + 1))]) + + self.log.debug(collection) + repre = self._create_representation( + frame_start, frame_end, collection=collection) + self.log.debug(repre) else: # in case it is file sequence but not new OTIO schema # `ImageSequenceReference` path = media_ref.target_url - dir_path, collection = pype.lib.make_sequence_collection( + collection_data = pype.lib.make_sequence_collection( path, trimmed_media_range, metadata) + self.staging_dir, collection = collection_data - # TODO: add representation - self.log.debug((dir_path, collection)) + self.log.debug(collection) + repre = self._create_representation( + frame_start, frame_end, collection=collection) + self.log.debug(repre) else: - path = media_ref.target_url - # TODO: add representation + dirname, filename = os.path.split(media_ref.target_url) + self.staging_dir = dirname + self.log.debug(path) + repre = self._create_representation( + frame_start, frame_end, file=filename) + self.log.debug(repre) + + if repre: + instance.data + instance.data["representations"].append(repre) + + def _create_representation(self, start, end, **kwargs): + """ + Creating representation data. + + Args: + start (int): start frame + end (int): end frame + kwargs (dict): optional data + + Returns: + dict: representation data + """ + + # create default representation data + representation_data = { + "frameStart": start, + "frameEnd": end, + "stagingDir": self.staging_dir + } + + if kwargs.get("collection"): + collection = kwargs.get("collection") + files = [f for f in collection] + ext = collection.format("{tail}") + representation_data.update({ + "name": ext[1:], + "ext": ext[1:], + "files": files, + "frameStart": start, + "frameEnd": end, + }) + return representation_data + if kwargs.get("file"): + file = kwargs.get("file") + ext = os.path.splitext(file)[-1] + representation_data.update({ + "name": ext[1:], + "ext": ext[1:], + "files": file, + "frameStart": start, + "frameEnd": end, + }) + return representation_data