|
868
|
1 |
/* Cinecast Cinelab Serializer */ |
|
|
2 |
|
|
864
|
3 |
if (typeof IriSP.serializers === "undefined") { |
|
|
4 |
IriSP.serializers = {} |
|
|
5 |
} |
|
|
6 |
|
|
|
7 |
IriSP.serializers.cinecast = { |
|
|
8 |
types : { |
|
|
9 |
media : { |
|
|
10 |
serialized_name : "medias", |
|
|
11 |
model_name : "media", |
|
|
12 |
deserializer : function(_data, _source) { |
|
|
13 |
var _res = new IriSP.Model.Media(_data.id, _source); |
|
866
|
14 |
_res.video = _data.url; |
|
864
|
15 |
_res.title = _data.meta.title; |
|
|
16 |
_res.description = _data.meta.synopsis; |
|
|
17 |
_res.setDuration(_data.meta.duration); |
|
|
18 |
return _res; |
|
|
19 |
}, |
|
|
20 |
serializer : function(_data, _source) { |
|
|
21 |
return { |
|
|
22 |
id : _source.unNamespace(_data.id), |
|
866
|
23 |
url : _data.video, |
|
864
|
24 |
meta : { |
|
|
25 |
title : _data.title, |
|
|
26 |
synopsis : _data.description, |
|
|
27 |
duration : _data.duration.milliseconds |
|
|
28 |
} |
|
|
29 |
} |
|
|
30 |
} |
|
|
31 |
}, |
|
|
32 |
tag : { |
|
|
33 |
serialized_name : "tags", |
|
|
34 |
model_name : "tag", |
|
|
35 |
deserializer : function(_data, _source) { |
|
|
36 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
|
37 |
_res.title = _data.meta.description; |
|
|
38 |
return _res; |
|
|
39 |
}, |
|
|
40 |
serializer : function(_data, _source) { |
|
|
41 |
return { |
|
|
42 |
id : _source.unNamespace(_data.id), |
|
|
43 |
meta : { |
|
|
44 |
description : _data.title |
|
|
45 |
} |
|
|
46 |
} |
|
|
47 |
} |
|
|
48 |
}, |
|
|
49 |
annotationType : { |
|
|
50 |
serialized_name : "annotation_types", |
|
|
51 |
deserializer : function(_data, _source) { |
|
|
52 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
|
53 |
_res.title = _source.getNamespaced(_data.id).name; |
|
|
54 |
_res.description = _data.meta.description; |
|
|
55 |
return _res; |
|
|
56 |
}, |
|
|
57 |
serializer : function(_data, _source) { |
|
|
58 |
return { |
|
|
59 |
id : _source.unNamespace(_data.id), |
|
|
60 |
meta : { |
|
|
61 |
description : _data.description |
|
|
62 |
} |
|
|
63 |
} |
|
|
64 |
} |
|
|
65 |
}, |
|
|
66 |
annotation : { |
|
|
67 |
serialized_name : "annotations", |
|
|
68 |
deserializer : function(_data, _source) { |
|
|
69 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
|
70 |
_res.title = _data.meta.creator_name; |
|
|
71 |
_res.description = _data.content.data; |
|
|
72 |
_res.created = IriSP.Model.isoToDate(_data.meta.created); |
|
|
73 |
var _c = parseInt(_data.color).toString(16); |
|
|
74 |
while (_c.length < 6) { |
|
|
75 |
_c = '0' + _c; |
|
|
76 |
} |
|
|
77 |
_res.color = '#' + _c; |
|
|
78 |
_res.setMedia(_data.media, _source); |
|
|
79 |
_res.setAnnotationType(_data.type); |
|
|
80 |
_res.setTags(IriSP._(_data.tags).map(function(_t) { |
|
|
81 |
if (typeof _source.contents.tag === "undefined") { |
|
|
82 |
_source.contents.tag = new IriSP.Model.List(_source.directory); |
|
|
83 |
} |
|
|
84 |
if (_source.contents.tag.hasId(_t)) { |
|
|
85 |
return _t; |
|
|
86 |
} else { |
|
|
87 |
var _id = _t.toLowerCase() |
|
|
88 |
.replace(/#/g,'') |
|
|
89 |
.replace(/^(\d)/,'_$1') |
|
|
90 |
.replace(/[áâäà ã]/g,'a') |
|
|
91 |
.replace(/ç/g,'c') |
|
|
92 |
.replace(/[éèêë]/g,'e') |
|
|
93 |
.replace(/[Ãìîï]/g,'i') |
|
|
94 |
.replace(/ñ/g,'n') |
|
|
95 |
.replace(/[óòôöõ]/g,'o') |
|
|
96 |
.replace(/Å“/g,'oe') |
|
|
97 |
.replace(/[úùûü]/g,'u') |
|
|
98 |
.replace(/ÿ/g,'y') |
|
|
99 |
.replace(/[^A-Za-z0-9_]/g,''), |
|
|
100 |
_tag = new IriSP.Model.Tag(_id, _source); |
|
|
101 |
_tag.title = _t; |
|
866
|
102 |
_source.contents.tag.push(_tag); |
|
864
|
103 |
return _id; |
|
|
104 |
} |
|
|
105 |
})); |
|
|
106 |
_res.setBegin(_data.begin); |
|
|
107 |
_res.setEnd(_data.end); |
|
|
108 |
_res.creator = _data.meta.creator; |
|
|
109 |
return _res; |
|
|
110 |
}, |
|
|
111 |
serializer : function(_data, _source) { |
|
|
112 |
return { |
|
|
113 |
id : _source.unNamespace(_data.id), |
|
|
114 |
content : { |
|
|
115 |
data : _data.description |
|
|
116 |
}, |
|
|
117 |
begin : _data.begin.milliseconds, |
|
|
118 |
end : _data.begin.milliseconds, |
|
|
119 |
media : _source.unNamespace(_data.media.contents), |
|
|
120 |
type : _source.unNamespace(_data.annotationType.contents), |
|
|
121 |
meta : { |
|
|
122 |
created : IriSP.Model.dateToIso(_data.created), |
|
|
123 |
creator : _data.creator, |
|
|
124 |
creator_name : _data.title |
|
|
125 |
}, |
|
|
126 |
tags : _data.getTags().map(function(_el) { |
|
|
127 |
return _source.unNamespace(_el.id) |
|
|
128 |
}) |
|
|
129 |
} |
|
|
130 |
} |
|
|
131 |
} |
|
|
132 |
}, |
|
|
133 |
serialize : function(_source) { |
|
|
134 |
var _res = { |
|
|
135 |
format : "http://advene.org/ns/cinelab/" |
|
|
136 |
}, |
|
|
137 |
_this = this, |
|
|
138 |
_nsls = _source.listNamespaces(true); |
|
|
139 |
_res.imports = []; |
|
|
140 |
for (var _i = 0; _i < _nsls.length; _i++) { |
|
|
141 |
if (typeof _source.directory.namespaces[_nsls[_i]] !== "undefined") { |
|
|
142 |
_res.imports.push({ |
|
|
143 |
id : _nsls[_i], |
|
|
144 |
url : _source.directory.namespaces[_nsls[_i]] |
|
|
145 |
}) |
|
|
146 |
} |
|
|
147 |
} |
|
866
|
148 |
_source.forEach(function(_list, _typename) { |
|
864
|
149 |
if (typeof _this.types[_typename] !== "undefined") { |
|
|
150 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
|
151 |
return _this.types[_typename].serializer(_el, _source); |
|
|
152 |
}); |
|
|
153 |
} |
|
|
154 |
}); |
|
|
155 |
return _res; |
|
|
156 |
}, |
|
|
157 |
deSerialize : function(_data, _source) { |
|
|
158 |
if (typeof _data.imports !== "undefined") { |
|
866
|
159 |
IriSP._(_data.imports).forEach(function(_import) { |
|
864
|
160 |
_source.directory.namespaces[_import.id] = _import.url; |
|
|
161 |
}) |
|
|
162 |
} |
|
866
|
163 |
IriSP._(this.types).forEach(function(_type, _typename) { |
|
864
|
164 |
var _listdata = _data[_type.serialized_name]; |
|
|
165 |
if (typeof _listdata !== "undefined") { |
|
|
166 |
var _list = new IriSP.Model.List(_source.directory); |
|
|
167 |
if (_listdata.hasOwnProperty("length")) { |
|
|
168 |
var _l = _listdata.length; |
|
|
169 |
for (var _i = 0; _i < _l; _i++) { |
|
866
|
170 |
_list.push(_type.deserializer(_listdata[_i], _source)); |
|
864
|
171 |
} |
|
|
172 |
} else { |
|
866
|
173 |
_list.push(_type.deserializer(_listdata, _source)); |
|
864
|
174 |
} |
|
|
175 |
_source.addList(_typename, _list); |
|
|
176 |
} |
|
|
177 |
}); |
|
|
178 |
|
|
|
179 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
866
|
180 |
_source.setCurrentMediaId(_data.meta.id); |
|
864
|
181 |
} |
|
|
182 |
_source.setDefaultCurrentMedia(); |
|
|
183 |
} |
|
868
|
184 |
} |
|
|
185 |
|