Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve: mediapool loader and inventory clearing plugins #140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
424e206
Refactor create_bin function to include a set_as_current parameter fo…
jakubjezek001 Feb 29, 2024
5ee9fca
Update client and pipeline imports, refactor transcoding library refe…
jakubjezek001 Feb 29, 2024
7d39123
Update metadata handling in LoadMedia class
jakubjezek001 Mar 6, 2024
cbe265a
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Mar 6, 2024
1f9b9c0
Update Resolve settings and LoadMedia plugin configurations:
jakubjezek001 Mar 6, 2024
b59c646
Reversing changes
jakubjezek001 Mar 12, 2024
ac4c811
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Mar 12, 2024
4f20ffb
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Mar 25, 2024
9c79113
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Mar 27, 2024
0844726
Fixing reported bug on updating mediapoolitem
jakubjezek001 Mar 27, 2024
15b23b1
Adapting Colorbleeds colorspace distribution
jakubjezek001 Mar 27, 2024
ac989d3
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Mar 27, 2024
30c98d9
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Mar 28, 2024
dac1c2b
Fix default setting
BigRoy Mar 28, 2024
78104de
Add description
BigRoy Mar 28, 2024
e610b74
Fix loader refactor to AYON
BigRoy Mar 28, 2024
9b3e400
Fix missing bracket
BigRoy Mar 28, 2024
dd39958
Fix default setting
BigRoy Mar 28, 2024
9e77ea5
Merge pull request #298 from BigRoy/enhancement/AY-2612-resolve-adapt…
jakubjezek001 Apr 3, 2024
0ca349a
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Apr 26, 2024
608a0d2
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 May 6, 2024
7b0a114
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 May 6, 2024
221a48c
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 May 28, 2024
3e96a31
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 May 30, 2024
ced0e9f
Merge branch 'develop' of https://github.com/ynput/ayon-core into enh…
BigRoy Jun 11, 2024
f861dfa
Fix refactor of `remove_unused_media_pool_items` location
BigRoy Jun 11, 2024
d39acab
Fix usage of undefined variable
BigRoy Jun 11, 2024
14781e7
Cosmetics
BigRoy Jun 11, 2024
7a72ecb
Fix refactor of imports
BigRoy Jun 11, 2024
a51b2b4
Add selected to label
BigRoy Jun 11, 2024
6321bb3
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
BigRoy Jun 11, 2024
1b64a83
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Jun 11, 2024
a0ba192
Rename resolve paths and update imports for media loading
jakubjezek001 Jun 11, 2024
40fcca5
Merge branch 'enhancement/AY-2612-resolve-adaptation-colorbleed-plugi…
BigRoy Jun 11, 2024
ee5d829
Remove subproject integration for Unreal Engine.
jakubjezek001 Jun 11, 2024
ea187da
Merge pull request #635 from BigRoy/enhancement/AY-2612-resolve-adapt…
jakubjezek001 Jun 11, 2024
9e4d1f1
Update version to 0.2.2 in package.py
jakubjezek001 Jun 11, 2024
21c8674
Bump addon version to 0.2.2
jakubjezek001 Jun 11, 2024
7b1c4a8
Refactor Resolve media loading logic for single files and sequences.
jakubjezek001 Jun 12, 2024
c241546
Refactor media import process in LoadMedia plugin
jakubjezek001 Jun 12, 2024
ca8d707
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Jun 12, 2024
13c8c88
Merge branch 'develop' into enhancement/AY-2612-resolve-adaptation-co…
jakubjezek001 Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions server_addon/resolve/client/ayon_resolve/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def get_new_timeline(timeline_name: str = None):
return new_timeline


def create_bin(name: str, root: object = None) -> object:
def create_bin(name: str,
root: object = None,
set_as_current: bool = True) -> object:
"""
Create media pool's folder.

Expand All @@ -156,6 +158,8 @@ def create_bin(name: str, root: object = None) -> object:
Args:
name (str): name of folder / bin, or hierarchycal name "parent/name"
root (resolve.Folder)[optional]: root folder / bin object
set_as_current (resolve.Folder)[optional]: Whether to set the
resulting bin as current folder or not.

Returns:
object: resolve.Folder
Expand All @@ -168,22 +172,24 @@ def create_bin(name: str, root: object = None) -> object:
if "/" in name.replace("\\", "/"):
child_bin = None
for bname in name.split("/"):
child_bin = create_bin(bname, child_bin or root_bin)
child_bin = create_bin(bname,
root=child_bin or root_bin,
set_as_current=set_as_current)
if child_bin:
return child_bin
else:
created_bin = None
# Find existing folder or create it
for subfolder in root_bin.GetSubFolderList():
if subfolder.GetName() in name:
if subfolder.GetName() == name:
created_bin = subfolder

if not created_bin:
new_folder = media_pool.AddSubFolder(root_bin, name)
media_pool.SetCurrentFolder(new_folder)
break
else:
created_bin = media_pool.AddSubFolder(root_bin, name)

if set_as_current:
media_pool.SetCurrentFolder(created_bin)

return media_pool.GetCurrentFolder()
return created_bin


def remove_media_pool_item(media_pool_item: object) -> bool:
Expand Down Expand Up @@ -272,8 +278,7 @@ def create_timeline_item(
# get all variables
project = get_current_project()
media_pool = project.GetMediaPool()
_clip_property = media_pool_item.GetClipProperty
clip_name = _clip_property("File Name")
clip_name = media_pool_item.GetClipProperty("File Name")
timeline = timeline or get_current_timeline()

# timing variables
Expand All @@ -298,16 +303,22 @@ def create_timeline_item(
if source_end:
clip_data["endFrame"] = source_end
if timecode_in:
# Note: specifying a recordFrame will fail to place the timeline
# item if there's already an existing clip at that time on the
# active track.
clip_data["recordFrame"] = timeline_in

# add to timeline
media_pool.AppendToTimeline([clip_data])
output_timeline_item = media_pool.AppendToTimeline([clip_data])[0]

output_timeline_item = get_timeline_item(
media_pool_item, timeline)
# Adding the item may fail whilst Resolve will still return a
# TimelineItem instance - however all `Get*` calls return None
# Hence, we check whether the result is valid
if output_timeline_item.GetDuration() is None:
output_timeline_item = None

assert output_timeline_item, AssertionError((
"Clip name '{}' was't created on the timeline: '{}' \n\n"
"Clip name '{}' wasn't created on the timeline: '{}' \n\n"
"Please check if correct track position is activated, \n"
"or if a clip is not already at the timeline in \n"
"position: '{}' out: '{}'. \n\n"
Expand Down Expand Up @@ -947,3 +958,13 @@ def get_reformated_path(path, padded=False, first=False):
else:
path = re.sub(num_pattern, "%d", path)
return path


def iter_all_media_pool_clips():
"""Recursively iterate all media pool clips in current project"""
root = get_current_project().GetMediaPool().GetRootFolder()
queue = [root]
for folder in queue:
for clip in folder.GetClipList():
yield clip
queue.extend(folder.GetSubFolderList())
24 changes: 24 additions & 0 deletions server_addon/resolve/client/ayon_resolve/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Basic avalon integration
"""
import os
import json
import contextlib
from collections import OrderedDict

Expand All @@ -12,6 +13,7 @@
schema,
register_loader_plugin_path,
register_creator_plugin_path,
register_inventory_action_path,
AVALON_CONTAINER_ID,
)
from ayon_core.host import (
Expand All @@ -38,6 +40,7 @@
PUBLISH_PATH = os.path.join(PLUGINS_DIR, "publish")
LOAD_PATH = os.path.join(PLUGINS_DIR, "load")
CREATE_PATH = os.path.join(PLUGINS_DIR, "create")
INVENTORY_PATH = os.path.join(PLUGINS_DIR, "inventory")

AVALON_CONTAINERS = ":AVALON_CONTAINERS"

Expand Down Expand Up @@ -65,6 +68,7 @@ def install(self):

register_loader_plugin_path(LOAD_PATH)
register_creator_plugin_path(CREATE_PATH)
register_inventory_action_path(INVENTORY_PATH)

# register callback for switching publishable
pyblish.register_callback("instanceToggled",
Expand Down Expand Up @@ -145,6 +149,26 @@ def ls():
and the Maya equivalent, which is in `avalon.maya.pipeline`
"""

# Media Pool instances from Load Media loader
for clip in lib.iter_all_media_pool_clips():
data = clip.GetMetadata(lib.pype_tag_name)
if not data:
continue
data = json.loads(data)

# If not all required data, skip it
required = ['schema', 'id', 'loader', 'representation']
if not all(key in data for key in required):
continue

container = {key: data[key] for key in required}
container["objectName"] = clip.GetName() # Get path in folders
container["namespace"] = clip.GetName()
container["name"] = clip.GetUniqueId()
container["_item"] = clip
yield container

# Timeline instances from Load Clip loader
# get all track items from current timeline
all_timeline_items = lib.get_current_timeline_items(filter=False)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ayon_core.pipeline import (
InventoryAction,
)
from ayon_core.pipeline.load.utils import remove_container


class RemoveUnusedMedia(InventoryAction):

label = "Remove Unused Selected Media"
icon = "trash"

@staticmethod
def is_compatible(container):
return (
container.get("loader") == "LoadMedia"
)

def process(self, containers):
any_removed = False
for container in containers:
media_pool_item = container["_item"]
usage = int(media_pool_item.GetClipProperty("Usage"))
name = media_pool_item.GetName()
if usage == 0:
print(f"Removing {name}")
remove_container(container)
any_removed = True
else:
print(f"Keeping {name} with usage: {usage}")

return any_removed
Loading
Loading