From 7fca4242382b7a137dd1d7e9cc8c6179773af153 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 25 Jul 2024 17:30:03 +0200 Subject: [PATCH] WIP on feature/AY-979_Resolve-update-to-new-publisher --- client/ayon_resolve/api/lib.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/client/ayon_resolve/api/lib.py b/client/ayon_resolve/api/lib.py index 932bfb2691..807ee60c07 100644 --- a/client/ayon_resolve/api/lib.py +++ b/client/ayon_resolve/api/lib.py @@ -1,7 +1,8 @@ import sys -import json import re import os +import json +import uuid import contextlib from typing import List, Dict, Any from opentimelineio import opentime @@ -40,6 +41,27 @@ self.pype_timeline_name = "OpenPypeTimeline" +def get_timeline_media_pool_item(timeline, root=None): + """Return MediaPoolItem from Timeline""" + + # Due to limitations in the Resolve API we can't get + # the media pool item directly from the timeline. + # We can find it by name, however names are not + # enforced to be unique across bins. So, we give it + # unique name. + original_name = timeline.GetName() + identifier = str(uuid.uuid4().hex) + try: + timeline.SetName(identifier) + for item in iter_all_media_pool_clips(root=root): + if item.GetName() != identifier: + continue + return item + finally: + # Revert to original name + timeline.SetName(original_name) + + @contextlib.contextmanager def maintain_current_timeline(to_timeline: object, from_timeline: object = None):