Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/py-opentimelineio/opentimelineio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
adapters,
hooks,
algorithms,
bundle,
url_utils,
versioning,
)
17 changes: 17 additions & 0 deletions src/py-opentimelineio/opentimelineio/bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the OpenTimelineIO project

__doc__ = """ Read and write timelines bundled with their media, as .otioz
files or .otiod directories. """

from . import _otio

MediaReferencePolicy = _otio.bundle.MediaReferencePolicy
WriteOptions = _otio.bundle.WriteOptions
ReadOptions = _otio.bundle.ReadOptions
file_from_url = _otio.bundle.file_from_url
dry_run = _otio.bundle.dry_run
write_otioz = _otio.bundle.write_otioz
read_otioz = _otio.bundle.read_otioz
write_otiod = _otio.bundle.write_otiod
read_otiod = _otio.bundle.read_otiod
42 changes: 42 additions & 0 deletions tests/test_otiod.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,48 @@ def test_media_policy_as_string(self):
relative_media_base_dir=temp_dir,
media_policy="not_a_policy")

def test_bundle_module(self):
with tempfile.TemporaryDirectory() as temp_dir:
tl = otio.schema.Timeline()
otiod_path = os.path.join(temp_dir, "module.otiod")
otio.bundle.write_otiod(tl, otiod_path)
self.assertIsNotNone(otio.bundle.read_otiod(otiod_path))

def test_dry_run(self):
with tempfile.TemporaryDirectory() as temp_dir:
tl = otio.schema.Timeline()
tr = otio.schema.Track()
tl.tracks.append(tr)
cl = otio.schema.Clip()
tr.append(cl)
media_path = os.path.join(temp_dir, "video.mov")
with open(media_path, "wb") as f:
f.write(b"\0" * 1000)
cl.media_reference = otio.schema.ExternalReference(
otio.url_utils.url_from_filepath(media_path))

# A dry run writes nothing, and the size includes the media
otiod_path = os.path.join(temp_dir, "dry_run.otiod")
size = otio.bundle.dry_run(tl)
self.assertEqual(
otio.adapters.write_to_file(tl, otiod_path, dryrun=True),
size)
self.assertFalse(os.path.exists(otiod_path))

with open(media_path, "wb") as f:
f.write(b"\0" * 3000)
self.assertEqual(otio.bundle.dry_run(tl), size + 2000)

# Non-file media is an error with the default policy
cl.media_reference = otio.schema.ExternalReference(
"http://example.com/video.mov")
with self.assertRaises(OSError):
otio.bundle.dry_run(tl)

options = otio.bundle.WriteOptions()
options.policy = otio.bundle.MediaReferencePolicy.all_missing
self.assertGreater(otio.bundle.dry_run(tl, options), 0)


if __name__ == "__main__":
unittest.main()
21 changes: 21 additions & 0 deletions tests/test_otioz.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ def test_target_schema_versions_from_env(self):
content = zf.read("content.otio").decode("utf-8")
self.assertIn('"Marker.2"', content)

def test_dry_run(self):
with tempfile.TemporaryDirectory() as temp_dir:
tl = otio.schema.Timeline()
tr = otio.schema.Track()
tl.tracks.append(tr)
cl = otio.schema.Clip()
tr.append(cl)
cl.media_reference = otio.schema.ExternalReference("video.mov")
with open(os.path.join(temp_dir, "video.mov"), "wb") as f:
f.write(b"\0" * 1000)

# The size includes the media, and nothing is written
otioz_path = os.path.join(temp_dir, "dry_run.otioz")
size = otio.adapters.write_to_file(
tl,
otioz_path,
relative_media_base_dir=temp_dir,
dryrun=True)
self.assertGreater(size, 1000)
self.assertFalse(os.path.exists(otioz_path))


if __name__ == "__main__":
unittest.main()
Loading