Skip to content

utils

get_marker_from_clip_index(otio_timeline, clip_index)

Parameters:

Name Type Description Default
otio_timeline Timeline

The otio timeline to inspect

required
clip_index int

The clip index metadata to retrieve.

required

Returns:

Name Type Description
tuple (Clip, Marker)

The associated clip and marker or (None, None)

Source code in client/ayon_resolve/otio/utils.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def get_marker_from_clip_index(otio_timeline, clip_index):
    """
    Args:
        otio_timeline (otio.Timeline): The otio timeline to inspect
        clip_index (int): The clip index metadata to retrieve.

    Returns:
        tuple(otio.Clip, otio.Marker): The associated clip and marker
            or (None, None)
    """
    try:  # opentimelineio >= 0.16.0
        all_clips = otio_timeline.find_clips()
    except AttributeError:  # legacy
        all_clips = otio_timeline.each_clip()

    # Retrieve otioClip from parent context otioTimeline
    # See collect_current_project
    for otio_clip in all_clips:
        for marker in otio_clip.markers:
            marker = unwrap_resolve_otio_marker(marker)
            if marker.metadata.get("clip_index") == clip_index:
                return  otio_clip, marker

    return None, None

get_padding_from_path(path)

Return padding number from DaVinci Resolve sequence path style

Parameters:

Name Type Description Default
path str

path url or simple file name

required

Returns:

Name Type Description
int

padding number

Example

get_padding_from_path("plate.[0001-1008].exr") > 4

Source code in client/ayon_resolve/otio/utils.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def get_padding_from_path(path):
    """
    Return padding number from DaVinci Resolve sequence path style

    Args:
        path (str): path url or simple file name

    Returns:
        int: padding number

    Example:
        get_padding_from_path("plate.[0001-1008].exr") > 4

    """
    padding_pattern = "(\\d+)(?=-)"
    if "[" in path:
        return len(re.findall(padding_pattern, path).pop())

    return None

get_reformated_path(path, padded=True, first=False)

Return fixed python expression path

Parameters:

Name Type Description Default
path str

path url or simple file name

required

Returns:

Name Type Description
type

string with reformatted path

Example

get_reformated_path("plate.[0001-1008].exr") > plate.%04d.exr

Source code in client/ayon_resolve/otio/utils.py
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
def get_reformated_path(path, padded=True, first=False):
    """
    Return fixed python expression path

    Args:
        path (str): path url or simple file name

    Returns:
        type: string with reformatted path

    Example:
        get_reformated_path("plate.[0001-1008].exr") > plate.%04d.exr

    """
    num_pattern = r"(\[\d+\-\d+\])"
    padding_pattern = r"(\d+)(?=-)"
    first_frame_pattern = re.compile(r"\[(\d+)\-\d+\]")

    if "[" in path:
        padding = len(re.findall(padding_pattern, path).pop())
        if padded:
            path = re.sub(num_pattern, f"%0{padding}d", path)
        elif first:
            first_frame = re.findall(first_frame_pattern, path, flags=0)
            if len(first_frame) >= 1:
                first_frame = first_frame[0]
            path = re.sub(num_pattern, first_frame, path)
        else:
            path = re.sub(num_pattern, "%d", path)
    return path

unwrap_resolve_otio_marker(marker)

Parameters:

Name Type Description Default
marker Marker

The marker to unwrap.

required

Returns:

Name Type Description
marker Marker

Conformed marker.

Source code in client/ayon_resolve/otio/utils.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def unwrap_resolve_otio_marker(marker):
    """
    Args:
        marker (opentimelineio.schema.Marker): The marker to unwrap.

    Returns:
        marker (opentimelineio.schema.Marker): Conformed marker.
    """
    # Resolve native OTIO exporter messes up the marker
    # dict metadata for some reasons.
    # {dict_info} -> {"Resolve_OTIO": {"Note": "string_dict_info"}}
    try:
        marker_note = marker.metadata["Resolve_OTIO"]["Note"]
    except KeyError:
        return marker

    marker_note_dict = json.loads(marker_note)
    marker.metadata.update(marker_note_dict)  # prevent additional resolve keys
    return marker