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_hiero/api/otio/utils.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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:

            try:
                json_metadata = marker.metadata["json_metadata"]
            except KeyError:
                continue

            else:
                metadata = json.loads(json_metadata)
                if 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_hiero/api/otio/utils.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)

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_hiero/api/otio/utils.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def get_reformated_path(path, padded=True):
    """
    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

    """
    if "%" in path:
        padding_pattern = r"(\d+)"
        padding = int(re.findall(padding_pattern, path).pop())
        num_pattern = r"(%\d+d)"
        if padded:
            path = re.sub(num_pattern, "%0{}d".format(padding), path)
        else:
            path = re.sub(num_pattern, "%d", path)
    return path