From e22aceab4b4a19ea6df0a0bf330b07fae009bf49 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 7 Dec 2020 18:47:39 +0100 Subject: [PATCH] feat(global): review otio add representation --- pype/lib/__init__.py | 6 +- pype/lib/editorial.py | 21 +++++++ .../global/publish/collect_otio_review.py | 55 ++++++++++++++----- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/pype/lib/__init__.py b/pype/lib/__init__.py index 6f8434d43e..93799d0232 100644 --- a/pype/lib/__init__.py +++ b/pype/lib/__init__.py @@ -61,7 +61,8 @@ from .ffmpeg_utils import ( from .editorial import ( is_overlapping_otio_ranges, - convert_otio_range_to_frame_range + convert_otio_range_to_frame_range, + convert_to_padded_path ) __all__ = [ @@ -110,5 +111,6 @@ __all__ = [ "_subprocess", "is_overlapping_otio_ranges", - "convert_otio_range_to_frame_range" + "convert_otio_range_to_frame_range", + "convert_to_padded_path" ] diff --git a/pype/lib/editorial.py b/pype/lib/editorial.py index 89f534b143..2381d4b518 100644 --- a/pype/lib/editorial.py +++ b/pype/lib/editorial.py @@ -1,3 +1,4 @@ +import re from opentimelineio.opentime import to_frames @@ -34,3 +35,23 @@ def is_overlapping_otio_ranges(test_otio_range, main_otio_range, strict=False): )) else: return covering_exp + + +def convert_to_padded_path(path, padding): + """ + Return correct padding in sequence string + + Args: + path (str): path url or simple file name + padding (int): number of padding + + Returns: + type: string with reformated path + + Example: + convert_to_padded_path("plate.%d.exr") > plate.%04d.exr + + """ + if "%d" in path: + path = re.sub("%d", "%0{padding}d".format(padding=padding), path) + return path diff --git a/pype/plugins/global/publish/collect_otio_review.py b/pype/plugins/global/publish/collect_otio_review.py index 0ab3cf8b8b..cf80445f8d 100644 --- a/pype/plugins/global/publish/collect_otio_review.py +++ b/pype/plugins/global/publish/collect_otio_review.py @@ -5,12 +5,10 @@ Requires: masterLayer -> instance data attribute otioClipRange -> instance data attribute """ +import os import opentimelineio as otio import pyblish.api -from pype.lib import ( - is_overlapping_otio_ranges, - convert_otio_range_to_frame_range -) +import pype.lib class CollectOcioReview(pyblish.api.InstancePlugin): @@ -38,26 +36,53 @@ class CollectOcioReview(pyblish.api.InstancePlugin): if track_name not in review_track_name: continue if isinstance(_otio_clip, otio.schema.Clip): - if is_overlapping_otio_ranges( + if pype.lib.is_overlapping_otio_ranges( parent_range, otio_clip_range, strict=False): self.create_representation( _otio_clip, otio_clip_range, instance) def create_representation(self, otio_clip, to_otio_range, instance): - to_timeline_start, to_timeline_end = convert_otio_range_to_frame_range( + to_tl_start, to_tl_end = pype.lib.convert_otio_range_to_frame_range( to_otio_range) - timeline_start, timeline_end = convert_otio_range_to_frame_range( + tl_start, tl_end = pype.lib.convert_otio_range_to_frame_range( otio_clip.range_in_parent()) - source_start, source_end = convert_otio_range_to_frame_range( + source_start, source_end = pype.lib.convert_otio_range_to_frame_range( otio_clip.source_range) media_reference = otio_clip.media_reference metadata = media_reference.metadata - available_start, available_end = convert_otio_range_to_frame_range( + mr_start, mr_end = pype.lib.convert_otio_range_to_frame_range( media_reference.available_range) path = media_reference.target_url - self.log.debug(path) - self.log.debug(metadata) - self.log.debug((available_start, available_end)) - self.log.debug((source_start, source_end)) - self.log.debug((timeline_start, timeline_end)) - self.log.debug((to_timeline_start, to_timeline_end)) + reference_frame_start = (mr_start + source_start) + ( + to_tl_start - tl_start) + reference_frame_end = (mr_start + source_end) - ( + tl_end - to_tl_end) + + base_name = os.path.basename(path) + staging_dir = os.path.dirname(path) + ext = os.path.splitext(base_name)[1][1:] + + if metadata.get("isSequence"): + files = list() + padding = metadata["padding"] + base_name = pype.lib.convert_to_padded_path(base_name, padding) + for index in range( + reference_frame_start, (reference_frame_end + 1)): + file_name = base_name % index + path_test = os.path.join(staging_dir, file_name) + if os.path.exists(path_test): + files.append(file_name) + + self.log.debug(files) + else: + files = base_name + + representation = { + "ext": ext, + "name": ext, + "files": files, + "frameStart": reference_frame_start, + "frameEnd": reference_frame_end, + "stagingDir": staging_dir + } + self.log.debug(representation)