7 media : { |
7 media : { |
8 serialized_name : "medias", |
8 serialized_name : "medias", |
9 model_name : "media", |
9 model_name : "media", |
10 deserializer : function(_data, _source) { |
10 deserializer : function(_data, _source) { |
11 var _res = new IriSP.Model.Media(_data.id, _source); |
11 var _res = new IriSP.Model.Media(_data.id, _source); |
12 _res.url = _data.href; |
12 _res.video = ( |
|
13 typeof _data.url !== "undefined" |
|
14 ? _data.url |
|
15 : ( |
|
16 typeof _data.href !== "undefined" |
|
17 ? _data.href |
|
18 : null |
|
19 ) |
|
20 ); |
|
21 if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
22 _res.streamer = _data.meta.item.value; |
|
23 } |
13 _res.title = _data.meta["dc:title"]; |
24 _res.title = _data.meta["dc:title"]; |
14 _res.description = _data.meta["dc:description"]; |
25 _res.description = _data.meta["dc:description"]; |
15 _res.setDuration(_data.meta["dc:duration"]); |
26 _res.setDuration(_data.meta["dc:duration"]); |
16 return _res; |
27 return _res; |
17 }, |
28 }, |
18 serializer : function(_data, _source) { |
29 serializer : function(_data, _source) { |
19 return { |
30 return { |
20 id : _source.unNamespace(_data.id), |
31 id : _source.unNamespace(_data.id), |
21 href : _data.url, |
32 url : _data.video, |
22 meta : { |
33 meta : { |
23 "dc:title" : _data.title, |
34 "dc:title" : _data.title, |
24 "dc:description" : _data.description, |
35 "dc:description" : _data.description, |
25 "dc:duration" : _data.duration.milliseconds |
36 "dc:duration" : _data.duration.milliseconds |
26 } |
37 } |
103 } |
114 } |
104 }, |
115 }, |
105 serialize : function(_source) { |
116 serialize : function(_source) { |
106 var _res = {}, |
117 var _res = {}, |
107 _this = this; |
118 _this = this; |
108 _source.each(function(_list, _typename) { |
119 _source.forEach(function(_list, _typename) { |
109 if (typeof _this.types[_typename] !== "undefined") { |
120 if (typeof _this.types[_typename] !== "undefined") { |
110 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
121 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
111 return _this.types[_typename].serializer(_el, _source); |
122 return _this.types[_typename].serializer(_el, _source); |
112 }); |
123 }); |
113 } |
124 } |
114 }); |
125 }); |
115 return _res; |
126 return _res; |
116 }, |
127 }, |
117 deSerialize : function(_data, _source) { |
128 deSerialize : function(_data, _source) { |
118 IriSP._(this.types).each(function(_type, _typename) { |
129 IriSP._(this.types).forEach(function(_type, _typename) { |
119 var _listdata = _data[_type.serialized_name]; |
130 var _listdata = _data[_type.serialized_name]; |
120 if (typeof _listdata !== "undefined") { |
131 if (typeof _listdata !== "undefined") { |
121 var _list = new IriSP.Model.List(_source.directory); |
132 var _list = new IriSP.Model.List(_source.directory); |
122 if (_listdata.hasOwnProperty("length")) { |
133 if (_listdata.hasOwnProperty("length")) { |
123 var _l = _listdata.length; |
134 var _l = _listdata.length; |
124 for (var _i = 0; _i < _l; _i++) { |
135 for (var _i = 0; _i < _l; _i++) { |
125 _list.addElement(_type.deserializer(_listdata[_i], _source)); |
136 _list.push(_type.deserializer(_listdata[_i], _source)); |
126 } |
137 } |
127 } else { |
138 } else { |
128 _list.addElement(_type.deserializer(_listdata, _source)); |
139 _list.push(_type.deserializer(_listdata, _source)); |
129 } |
140 } |
130 _source.addList(_typename, _list); |
141 _source.addList(_typename, _list); |
131 } |
142 } |
132 }); |
143 }); |
133 |
144 |