Permalink
Browse files

Refactor media reference (#204)

* Moving `media_reference` into core.
* Adding .DS_store on mac to gitignore.
* Refactor `ExternalReference` and `MissingReference` out into `schema` library.
  • Loading branch information...
ssteinbach committed Jan 11, 2018
1 parent 1fc1095 commit 520d5270975b64d5cf675c61a741937253540a77
View
@@ -4,3 +4,4 @@ build*
dist*
*.egg-info
.coverage
.DS_store
View
@@ -92,7 +92,7 @@ def _parse_data_line(line, columns, fps):
if metadata.get("Source File"):
source = metadata.pop("Source File")
clip.media_reference = otio.media_reference.External(
clip.media_reference = otio.schema.ExternalReference(
target_url=source
)
@@ -162,7 +162,7 @@ def _read_shot(shot):
start = int(cmds.shot(shot, q=True, startTime=True))
end = int(cmds.shot(shot, q=True, endTime=True)) + 1
video_reference = otio.media_reference.External(
video_reference = otio.schema.ExternalReference(
target_url=_video_url_for_shot(shot),
available_range=otio.opentime.TimeRange(
otio.opentime.RationalTime(value=start, rate=rate),
@@ -246,7 +246,7 @@ def _write_item(it, to_session):
it.media_reference and
isinstance(
it.media_reference,
otio.media_reference.External
otio.schema.ExternalReference
)
):
src.setMedia([str(it.media_reference.target_url)])
@@ -44,7 +44,7 @@
t.tracks.append(track)
# Make a prototype media ref with the fragment's initialization metadata
fragmented_media_ref = otio.media_reference.External(
fragmented_media_ref = otio.schema.ExternalReference(
target_url='video1.mp4',
metadata={
"streaming": {
@@ -880,7 +880,7 @@ def _handle_BYTERANGE(self, entry, playlist_version, clip):
def _parse_entries(self, playlist_entries, playlist_version):
"""Interpret the entries through the lens of the schema"""
current_media_ref = otio.media_reference.External(
current_media_ref = otio.schema.ExternalReference(
metadata={
FORMAT_METADATA_KEY: {},
STREAMING_METADATA_KEY: {}
@@ -911,7 +911,7 @@ def _parse_entries(self, playlist_entries, playlist_version):
current_track += 1
# Set up the next segment definition
current_media_ref = otio.media_reference.External(
current_media_ref = otio.schema.ExternalReference(
metadata={
FORMAT_METADATA_KEY: {},
STREAMING_METADATA_KEY: {}
@@ -130,7 +130,7 @@ def test_media_pl_from_mem(self):
t.tracks.append(track)
# Make a prototype media ref with the segment's initialization metadata
segmented_media_ref = otio.media_reference.External(
segmented_media_ref = otio.schema.ExternalReference(
target_url='video1.mp4',
metadata={
"streaming": {
@@ -662,7 +662,7 @@ def test_explicit_master_pl_from_mem(self):
t.tracks.append(track)
# Make a prototype media ref with the segment's initialization metadata
segmented_media_ref = otio.media_reference.External(
segmented_media_ref = otio.schema.ExternalReference(
target_url='video1.mp4',
metadata={
'streaming': {
View
@@ -125,7 +125,7 @@ def _conform_timeline(timeline, folder):
continue
# if we found one, then relink to the new path
clip.media_reference = otio.media_reference.External(
clip.media_reference = otio.schema.ExternalReference(
target_url="file://" + new_path,
available_range=None # we don't know the available range
)
View
@@ -127,7 +127,7 @@ def _timeline_with_single_clip(name, full_path, dryrun=False):
fps = _ffprobe_fps(name, full_path, dryrun)
available_range = _media_start_end_of(full_path, fps)
media_reference = otio.media_reference.External(
media_reference = otio.schema.ExternalReference(
target_url="file://" + full_path,
available_range=available_range
)
@@ -186,7 +186,7 @@ def _timeline_with_breaks(name, full_path, dryrun=False):
available_range = _media_start_end_of(full_path, fps)
clip.media_reference = otio.media_reference.External(
clip.media_reference = otio.schema.ExternalReference(
target_url="file://" + full_path,
available_range=available_range
)
@@ -36,10 +36,8 @@
opentime,
exceptions,
core,
media_reference,
schema,
plugins,
adapters,
media_linker,
algorithms,
)
@@ -319,12 +319,12 @@ def make_clip(self, comment_data):
clip.name = str(self.clip_num)
if 'media_reference' in comment_data:
clip.media_reference = otio.media_reference.External()
clip.media_reference = otio.schema.ExternalReference()
clip.media_reference.target_url = comment_data[
'media_reference'
]
else:
clip.media_reference = otio.media_reference.MissingReference()
clip.media_reference = otio.schema.MissingReference()
# this could currently break without a 'FROM CLIP' comment.
# Without that there is no 'media_reference' Do we have a default
@@ -66,16 +66,16 @@ def _resolved_backreference(elem, tag, element_map):
def _populate_backreference_map(item, br_map):
if isinstance(item, otio.media_reference.MediaReference):
if isinstance(item, otio.core.MediaReference):
tag = 'file'
elif isinstance(item, otio.schema.Track):
tag = 'sequence'
else:
tag = None
if isinstance(item, otio.media_reference.External):
if isinstance(item, otio.schema.ExternalReference):
item_hash = hash(str(item.target_url))
elif isinstance(item, otio.media_reference.MissingReference):
elif isinstance(item, otio.schema.MissingReference):
item_hash = 'missing_ref'
else:
item_hash = item.__hash__()
@@ -111,9 +111,9 @@ def singleton_decorator(func):
@functools.wraps(func)
def wrapper(item, *args, **kwargs):
br_map = args[-1]
if isinstance(item, otio.media_reference.External):
if isinstance(item, otio.schema.ExternalReference):
item_hash = hash(str(item.target_url))
elif isinstance(item, otio.media_reference.MissingReference):
elif isinstance(item, otio.schema.MissingReference):
item_hash = 'missing_ref'
else:
item_hash = item.__hash__()
@@ -219,7 +219,7 @@ def _parse_media_reference(file_e, element_map):
duration=otio.opentime.RationalTime(duration, file_rate)
)
return otio.media_reference.External(
return otio.schema.ExternalReference(
target_url=url.strip(),
available_range=available_range
)
@@ -789,7 +789,7 @@ def _build_item(item, timeline_range, transition_offsets, br_map):
elif isinstance(item, otio.schema.Clip):
if isinstance(
item.media_reference,
otio.media_reference.MissingReference
otio.schema.MissingReference
):
return _build_clip_item_without_media(
item,
@@ -26,7 +26,9 @@
# flake8: noqa
from . import serializable_object
from . import (
serializable_object,
)
from .serializable_object import (
SerializableObject,
serializable_field,
@@ -56,3 +58,6 @@
deserialize_json_from_string,
deserialize_json_from_file,
)
from .media_reference import (
MediaReference,
)
@@ -24,14 +24,17 @@
"""Media Reference Classes and Functions."""
from . import (
from .. import (
opentime,
core,
)
from . import (
type_registry,
serializable_object,
)
@core.register_type
class MediaReference(core.SerializableObject):
@type_registry.register_type
class MediaReference(serializable_object.SerializableObject):
"""Base Media Reference Class.
Currently handles string printing the child classes, which expose interface
@@ -49,22 +52,22 @@ def __init__(
available_range=None,
metadata=None
):
core.SerializableObject.__init__(self)
serializable_object.SerializableObject.__init__(self)
self.name = name
self.available_range = available_range
self.metadata = metadata or {}
name = core.serializable_field(
name = serializable_object.serializable_field(
"name",
doc="Name of this media reference."
)
available_range = core.serializable_field(
available_range = serializable_object.serializable_field(
"available_range",
opentime.TimeRange,
doc="Available range of media in this media reference."
)
metadata = core.serializable_field(
metadata = serializable_object.serializable_field(
"metadata",
dict,
doc="Metadata dictionary."
@@ -84,7 +87,7 @@ def __str__(self):
def __repr__(self):
return (
"otio.media_reference.{}("
"otio.schema.{}("
"name={},"
" available_range={},"
" metadata={}"
@@ -103,62 +106,3 @@ def __hash__(self, other):
self.available_range,
self.metadata
)
@core.register_type
class MissingReference(MediaReference):
"""Represents media for which a concrete reference is missing."""
_serializable_label = "MissingReference.1"
_name = "MissingReference"
@property
def is_missing_reference(self):
return True
@core.register_type
class External(MediaReference):
"""Reference to media via a url, for example "file:///var/tmp/foo.mov" """
_serializable_label = "ExternalReference.1"
_name = "External"
def __init__(
self,
target_url=None,
available_range=None,
metadata=None,
):
MediaReference.__init__(
self,
available_range=available_range,
metadata=metadata
)
self.target_url = target_url
target_url = core.serializable_field(
"target_url",
doc=(
"URL at which this media lives. For local references, use the "
"'file://' format."
)
)
def __str__(self):
return 'External("{}")'.format(self.target_url)
def __repr__(self):
return 'otio.media_reference.External(target_url={})'.format(
repr(self.target_url)
)
def __hash__(self, other):
return hash(
self.name,
self._name,
self.available_range,
self.target_url,
self.metadata
)
@@ -26,11 +26,11 @@
produce MediaReferences that point at valid, site specific media.
They expose a "link_media_reference" function with the signature:
link_media_reference :: otio.schema.Clip -> otio.media_reference.MediaReference
link_media_reference :: otio.schema.Clip -> otio.core.MediaReference
or:
def linked_media_reference(from_clip):
result = otio.media_reference.MediaReference() # whichever subclass
result = otio.core.MediaReference() # whichever subclass
# do stuff
return result
@@ -26,6 +26,12 @@
"""User facing classes."""
from .missing_reference import (
MissingReference
)
from .external_reference import (
ExternalReference
)
from .clip import (
Clip,
)
@@ -26,9 +26,11 @@
from .. import (
core,
media_reference as mr,
exceptions,
)
from . import (
missing_reference
)
@core.register_type
@@ -58,27 +60,27 @@ def __init__(
self.name = name
if not media_reference:
media_reference = mr.MissingReference()
media_reference = missing_reference.MissingReference()
self._media_reference = media_reference
name = core.serializable_field("name", doc="Name of this clip.")
transform = core.deprecated_field()
_media_reference = core.serializable_field(
"media_reference",
mr.MediaReference,
core.MediaReference,
"Media reference to the media this clip represents."
)
@property
def media_reference(self):
if self._media_reference is None:
self._media_reference = mr.MissingReference()
self._media_reference = missing_reference.MissingReference()
return self._media_reference
@media_reference.setter
def media_reference(self, val):
if val is None:
val = mr.MissingReference()
val = missing_reference.MissingReference()
self._media_reference = val
def available_range(self):
Oops, something went wrong.

0 comments on commit 520d527

Please sign in to comment.