Source code for cgl.plugins.otio.tools.fcp.fcp_media_linker
import os
from urllib import parse
import opentimelineio as otio
[docs]
def register_media_linker():
active_manifest = otio.plugins.manifest.ActiveManifest()
for linker in active_manifest.media_linkers:
if linker.name == "fcp_media_linker":
return
print(f"registering media linker: {__file__}")
linker = otio.media_linker.MediaLinker("fcp_media_linker", __file__)
active_manifest.media_linkers.insert(0, linker)
remaps = [('/Productions', "Z:"), ('/productions', "Z:")]
[docs]
def link_media_reference(in_clip, media_linker_argument_map):
if not isinstance(in_clip, otio.schema.Clip):
return
media_ref = in_clip.media_reference
if media_ref and isinstance(media_ref, otio.schema.GeneratorReference):
missing_ref = otio.schema.MissingReference()
# # missing_ref.metadata['original_url'] = media_ref.target_url
in_clip.media_reference = missing_ref
if media_ref and isinstance(media_ref, otio.schema.ExternalReference):
url = parse.urlparse(parse.unquote(media_ref.target_url), allow_fragments=False)
# check unc path
path = parse.unquote(media_ref.target_url).replace("file:", "")
if not os.path.exists(path):
path = url.path
# check local drive letter path
if not os.path.exists(path):
path = url.path.lstrip("/")
if not os.path.exists(path):
for a, b in remaps:
path = url.path.replace(a, b)
if os.path.exists(path):
break
if not os.path.exists(path):
# print(f"unable to locate {url.path}")
missing_ref = otio.schema.MissingReference()
missing_ref.metadata['original_url'] = url.path
in_clip.media_reference = missing_ref
available_range = in_clip.media_reference.available_range
metadata = in_clip.media_reference.metadata
in_clip.media_reference = otio.schema.ExternalReference(
target_url = path,
available_range = available_range,
metadata = metadata
)