-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_reference.go
More file actions
121 lines (105 loc) · 3.41 KB
/
external_reference.go
File metadata and controls
121 lines (105 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
116
117
118
119
120
121
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
package gotio
import (
"encoding/json"
"github.com/Avalanche-io/gotio/opentime"
)
// ExternalReferenceSchema is the schema for ExternalReference.
var ExternalReferenceSchema = Schema{Name: "ExternalReference", Version: 1}
// ExternalReference represents a URL-based media reference.
type ExternalReference struct {
MediaReferenceBase
targetURL string
}
// NewExternalReference creates a new ExternalReference.
func NewExternalReference(
name string,
targetURL string,
availableRange *opentime.TimeRange,
metadata AnyDictionary,
) *ExternalReference {
return &ExternalReference{
MediaReferenceBase: NewMediaReferenceBase(name, availableRange, metadata, nil),
targetURL: targetURL,
}
}
// TargetURL returns the target URL.
func (e *ExternalReference) TargetURL() string {
return e.targetURL
}
// SetTargetURL sets the target URL.
func (e *ExternalReference) SetTargetURL(targetURL string) {
e.targetURL = targetURL
}
// SchemaName returns the schema name.
func (e *ExternalReference) SchemaName() string {
return ExternalReferenceSchema.Name
}
// SchemaVersion returns the schema version.
func (e *ExternalReference) SchemaVersion() int {
return ExternalReferenceSchema.Version
}
// Clone creates a deep copy.
func (e *ExternalReference) Clone() SerializableObject {
return &ExternalReference{
MediaReferenceBase: MediaReferenceBase{
SerializableObjectWithMetadataBase: SerializableObjectWithMetadataBase{
name: e.name,
metadata: CloneAnyDictionary(e.metadata),
},
availableRange: cloneAvailableRange(e.availableRange),
availableImageBounds: cloneBox2d(e.availableImageBounds),
},
targetURL: e.targetURL,
}
}
// IsEquivalentTo returns true if equivalent.
func (e *ExternalReference) IsEquivalentTo(other SerializableObject) bool {
otherE, ok := other.(*ExternalReference)
if !ok {
return false
}
return e.name == otherE.name && e.targetURL == otherE.targetURL
}
// externalReferenceJSON is the JSON representation.
type externalReferenceJSON struct {
Schema string `json:"OTIO_SCHEMA"`
Name string `json:"name"`
Metadata AnyDictionary `json:"metadata"`
AvailableRange *opentime.TimeRange `json:"available_range"`
AvailableImageBounds *Box2d `json:"available_image_bounds"`
TargetURL string `json:"target_url"`
}
// MarshalJSON implements json.Marshaler.
func (e *ExternalReference) MarshalJSON() ([]byte, error) {
return json.Marshal(&externalReferenceJSON{
Schema: ExternalReferenceSchema.String(),
Name: e.name,
Metadata: e.metadata,
AvailableRange: e.availableRange,
AvailableImageBounds: e.availableImageBounds,
TargetURL: e.targetURL,
})
}
// UnmarshalJSON implements json.Unmarshaler.
func (e *ExternalReference) UnmarshalJSON(data []byte) error {
var j externalReferenceJSON
if err := json.Unmarshal(data, &j); err != nil {
return err
}
e.name = j.Name
e.metadata = j.Metadata
if e.metadata == nil {
e.metadata = make(AnyDictionary)
}
e.availableRange = j.AvailableRange
e.availableImageBounds = j.AvailableImageBounds
e.targetURL = j.TargetURL
return nil
}
func init() {
RegisterSchema(ExternalReferenceSchema, func() SerializableObject {
return NewExternalReference("", "", nil, nil)
})
}