# HG changeset patch # User veltr # Date 1330535594 -3600 # Node ID 7968346b968970e29ab8c8acdf339314521a61dd # Parent 9b8e68803f6fe656f564fd2301524837d966045e Added compatibility with cinecast format (with get_aliased) diff -r 9b8e68803f6f -r 7968346b9689 src/js/serializers/JSONSerializer.js --- a/src/js/serializers/JSONSerializer.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/serializers/JSONSerializer.js Wed Feb 29 18:13:14 2012 +0100 @@ -286,29 +286,23 @@ We've got to jump through a few hoops because the json sometimes defines fields with underscores and sometimes with dashes */ - var annotation_types = this._data.views[0]["annotation_types"]; - if (IriSP.null_or_undefined(annotation_types)) { - annotation_types = this._data.views[0]["annotation-types"]; - if (IriSP.null_or_undefined(annotation_types)) { + var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]); + if (annotation_types === null) { console.log("neither view.annotation_types nor view.annotation-types are defined"); return; - } } - var available_types = this._data["annotation_types"]; - if (IriSP.null_or_undefined(available_types)) { - available_types = this._data["annotation-types"]; - if (IriSP.null_or_undefined(available_types)) { - console.log("neither annotation_types nor annotation-types are defined"); + var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); + if (available_types === null) { + console.log("neither view.annotation_types nor view.annotation-types are defined"); return; - } } var potential_types = []; // Get the list of types which contain "Tw" in their content for (var i = 0; i < available_types.length; i++) { - if (/Tw/i.test(available_types[i]["dc:title"])) { + if (/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title']))) { potential_types.push(available_types[i].id); } } @@ -329,29 +323,23 @@ We've got to jump through a few hoops because the json sometimes defines fields with underscores and sometimes with dashes */ - var annotation_types = this._data.views[0]["annotation_types"]; - if (IriSP.null_or_undefined(annotation_types)) { - annotation_types = this._data.views[0]["annotation-types"]; - if (IriSP.null_or_undefined(annotation_types)) { + var annotation_types = IriSP.get_aliased(this._data.views[0], ["annotation_types", "annotation-types"]); + if (annotation_types === null) { console.log("neither view.annotation_types nor view.annotation-types are defined"); return; - } } - var available_types = this._data["annotation_types"]; - if (IriSP.null_or_undefined(available_types)) { - available_types = this._data["annotation-types"]; - if (IriSP.null_or_undefined(available_types)) { - console.log("neither annotation_types nor annotation-types are defined"); + var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); + if (available_types === null) { + console.log("neither view.annotation_types nor view.annotation-types are defined"); return; - } } var potential_types = []; // Get the list of types which do not contain "Tw" in their content for (var i = 0; i < available_types.length; i++) { - if (!(/Tw/i.test(available_types[i]["dc:title"]))) { + if (!(/Tw/i.test(IriSP.get_aliased(available_types[i], ['dc:title', 'title'])))) { potential_types.push(available_types[i].id); } } @@ -367,17 +355,19 @@ @param name of the ligne de temps */ IriSP.JSONSerializer.prototype.getId = function(name) { - if (IriSP.null_or_undefined(this._data["annotation-types"])) + var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); + + if (available_types == null) return; name = name.toUpperCase(); var e; - e = IriSP.underscore.find(this._data["annotation-types"], - function(entry) { - if (IriSP.null_or_undefined(entry["dc:title"])) - return false; - - return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); + e = IriSP.underscore.find(available_types, + function(entry) { + if (IriSP.get_aliased(entry, ['dc:title', 'title']) === null) + return false; + return (entry["dc:title"].toUpperCase().indexOf(name) !== -1); + }); if (typeof(e) === "undefined") return; @@ -391,13 +381,15 @@ @param name of the ligne de temps */ IriSP.JSONSerializer.prototype.getIds = function(name) { - if (IriSP.null_or_undefined(this._data["annotation-types"])) + var available_types = IriSP.get_aliased(this._data, ["annotation_types", "annotation-types"]); + + if (available_types == null) return; name = name.toUpperCase(); var e = []; - e = IriSP.underscore.filter(this._data["annotation-types"], - function(entry) { return (entry["dc:title"].toUpperCase().indexOf(name) !== -1) }); + e = IriSP.underscore.filter(available_types, + function(entry) { return (IriSP.get_aliased(entry, ['dc:title', 'title']).toUpperCase().indexOf(name) !== -1) }); return IriSP.underscore.pluck(e, "id"); }; @@ -440,4 +432,8 @@ val = this.getId("Publ"); return val; -}; \ No newline at end of file +}; + +IriSP.JSONSerializer.prototype.getDuration = function() { + return +(IriSP.get_aliased(this.currentMedia().meta, ["dc:duration", "duration"]) || 0); +} diff -r 9b8e68803f6f -r 7968346b9689 src/js/utils.js --- a/src/js/utils.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/utils.js Wed Feb 29 18:13:14 2012 +0100 @@ -157,6 +157,17 @@ return (typeof(val) === "undefined" || val === null); }; +/** get a property that can have multiple names **/ + +IriSP.get_aliased = function(_obj, _aliases) { + for (var _i = 0; _i < _aliases.length; _i++) { + if (typeof _obj[_aliases[_i]] !== "undefined") { + return _obj[_aliases[_i]]; + } + } + return null; +} + /** issue a call to an url shortener and return the shortened url */ IriSP.shorten_url = function(url) { if (IriSP.config.shortener.hasOwnProperty("shortening_function")) diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/annotationsListWidget.js --- a/src/js/widgets/annotationsListWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/annotationsListWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -110,7 +110,7 @@ var platf_url = IriSP.widgetsDefaults["AnnotationsListWidget"].ajax_url .replace(/\{/g, '{{').replace(/\}/g, '}}'); var media_id = this._serializer.currentMedia()["id"]; - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); var begin_timecode = (Math.floor(tcode) - 300) * 1000; if (begin_timecode < 0) diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/annotationsWidget.js --- a/src/js/widgets/annotationsWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/annotationsWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -19,7 +19,7 @@ var keywords = ""; var begin = +annotation.begin / 1000; var end = +annotation.end / 1000; - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); var tags = ""; var title_templ = "{{title}} - ( {{begin}} - {{end}} )"; @@ -34,7 +34,7 @@ var tag_list = {}; for (var i = 0; i < this._serializer._data.tags.length; i++) { var id = this._serializer._data.tags[i]["id"]; - var keyword = this._serializer._data.tags[i]["meta"]["dc:title"]; + var keyword = IriSP.get_aliased(this._serializer._data.tags[i]["meta"], ["dc:title", "title"]); tag_list[id] = keyword; } diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/arrowWidget.js --- a/src/js/widgets/arrowWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/arrowWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -43,7 +43,7 @@ var begin = (+ currentAnnotation.begin) / 1000; var end = (+ currentAnnotation.end) / 1000; - var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var middle_time = (begin + end) / 2; var percents = middle_time / duration; diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/createAnnotationWidget.js --- a/src/js/widgets/createAnnotationWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/createAnnotationWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -200,7 +200,7 @@ // block the arrow. this._Popcorn.trigger("IriSP.ArrowWidget.blockArrow"); - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); var currentChapter = this._serializer.currentChapitre(currentTime); @@ -379,13 +379,13 @@ var annotation = apiJson["annotations"][0]; annotation["media"] = this._serializer.currentMedia()["id"]; - var duration_part = Math.round(this._serializer.currentMedia().meta["dc:duration"] / 20); + var duration_part = Math.round(this._serializer.getDuration() / 20); if (this.cinecast_version) { annotation["begin"] = Math.round(this._Popcorn.currentTime() * 1000 - duration_part); annotation["end"] = Math.round(this._Popcorn.currentTime() * 1000 + duration_part); } else { - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); annotation["begin"] = +((duration * (this.sliceLeft / 100)).toFixed(0)); annotation["end"] = +((duration * ((this.sliceWidth + this.sliceLeft) / 100)).toFixed(0)); } @@ -394,8 +394,8 @@ if (annotation["begin"] < 0) annotation["begin"] = 0; - if (annotation["end"] > this._serializer.currentMedia().meta["dc:duration"]) - annotation["end"] = this._serializer.currentMedia().meta["dc:duration"]; + if (annotation["end"] > this._serializer.getDuration()) + annotation["end"] = this._serializer.getDuration(); annotation["type"] = this._serializer.getContributions(); @@ -444,7 +444,8 @@ var tmp_view = {"dc:contributor": "perso", "dc:creator": "perso", "dc:title": "Contributions", "id": json.annotations[0].type} - this._serializer._data["annotation-types"].push(tmp_view); + + IriSP.get_aliased(this._serializer._data, ["annotation_types", "annotation-types"]).push(tmp_view); } delete annotation.tags; diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/playerWidget.js --- a/src/js/widgets/playerWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/playerWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -69,7 +69,7 @@ } // we get it at each call because it may change. - var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var totalTime = IriSP.secondsToTime(duration); var elapsedTime = IriSP.secondsToTime(this._Popcorn.currentTime()); diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/polemicWidget.js --- a/src/js/widgets/polemicWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/polemicWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -51,7 +51,7 @@ var lineSize = this.width; // timeline pixel width var nbrframes = lineSize/frameSize; // frame numbers var numberOfTweet = 0; // number of tweet overide later - var duration = +this._serializer.currentMedia().meta["dc:duration"]; // timescale width + var duration = this._serializer.getDuration(); // timescale width var frameLength = lineSize / frameSize; // frame timescale var timeline; var colors = new Array("","#1D973D","#C5A62D","#CE0A15","#036AAE","#585858"); @@ -171,9 +171,10 @@ && typeof(item.meta["id-ref"]) !== "undefined" && item.meta["id-ref"] === view_type) { - var MyTJson = {}; - if (typeof(item.meta['dc:source']) !== "undefined") { - var MyTJson = JSON.parse(item.meta['dc:source']['content']); + var MyTJson = {}, + _source = IriSP.get_aliased(item.meta, ['dc:source', 'source']); + if (_source !== null) { + var MyTJson = JSON.parse(_source['content']); } if (item.content['polemics'] != undefined @@ -381,7 +382,7 @@ IriSP.PolemicWidget.prototype.sliderUpdater = function() { var time = +this._Popcorn.currentTime(); - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); this.paperSlider.attr("width", time * (this.width / (duration / 1000))); diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/segmentsWidget.js --- a/src/js/widgets/segmentsWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/segmentsWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -16,7 +16,7 @@ IriSP.SegmentsWidget.prototype.segmentToPixel = function(annotation) { var begin = Math.round((+ annotation.begin) / 1000); var end = Math.round((+ annotation.end) / 1000); - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var startPourcent = IriSP.timeToPourcent(begin, duration); var startPixel = Math.floor(this.selector.parent().width() * (startPourcent / 100)); @@ -79,7 +79,7 @@ var annotation = segments_annotations[i]; var begin = (+ annotation.begin); var end = (+ annotation.end); - var duration = this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); var id = annotation.id; var startPixel = Math.floor(this.selector.parent().width() * (begin / duration)); @@ -224,7 +224,7 @@ }; IriSP.SegmentsWidget.prototype.positionUpdater = function() { - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var time = this._Popcorn.currentTime(); //var position = ((time / duration) * 100).toFixed(2); var position = ((time / duration) * 100).toFixed(2); diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/sliderWidget.js --- a/src/js/widgets/sliderWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/sliderWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -52,7 +52,7 @@ var time = this._Popcorn.currentTime(); - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var percents = time / duration; /* we do these complicated calculations to center exactly @@ -92,7 +92,7 @@ var width = this.sliderBackground.width(); var relX = event.pageX - parentOffset.left; - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.currentTime(newTime); @@ -105,7 +105,7 @@ var width = this.sliderBackground.width(); var relX = event.pageX - parentOffset.left; - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.currentTime(newTime); @@ -161,7 +161,7 @@ var width = this.sliderBackground.width(); var relX = event.pageX - parentOffset.left; - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.currentTime(newTime); diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/sparklineWidget.js --- a/src/js/widgets/sparklineWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/sparklineWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -44,7 +44,7 @@ } else { console.log("sparklinewidget : computing stats ourselves"); var num_columns = (this.selector.width()) / IriSP.widgetsDefaults["SparklineWidget"].column_width; - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); var time_step = duration / num_columns; /* the time interval between two columns */ var results = []; var i = 0; /* the index in the loop */ @@ -91,7 +91,7 @@ /** react to a timeupdate event */ IriSP.SparklineWidget.prototype.timeUpdateHandler = function() { var currentTime = this._Popcorn.currentTime(); - var duration = +this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var proportion = ((currentTime / duration) * 100).toFixed(4); IriSP.jQuery(".Ldt-sparkLinePositionMarker").css("width", proportion + "%"); @@ -111,7 +111,7 @@ var width = this.selector.width(); var relX = event.pageX - parentOffset.left; - var duration = this._serializer.currentMedia().meta["dc:duration"] / 1000; + var duration = this._serializer.getDuration() / 1000; var newTime = ((relX / width) * duration).toFixed(2); this._Popcorn.trigger("IriSP.SparklineWidget.clicked", newTime); @@ -121,7 +121,7 @@ /** react when a new annotation is added */ IriSP.SparklineWidget.prototype.handleNewAnnotation = function(annotation) { var num_columns = this._results.length; - var duration = +this._serializer.currentMedia().meta["dc:duration"]; + var duration = this._serializer.getDuration(); var time_step = Math.round(duration / num_columns); /* the time interval between two columns */ var begin = +annotation.begin; var end = +annotation.end; diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/stackGraphWidget.js --- a/src/js/widgets/stackGraphWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/stackGraphWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -45,7 +45,7 @@ : _defaultDefColor); this.paper = new Raphael(this.selector[0], this.width, this.height); this.groups = []; - this.duration = this._serializer.currentMedia().meta["dc:duration"]; + this.duration = this._serializer.getDuration(); var _annotationType = this._serializer.getTweets(), _sliceDuration = ~~ ( this.duration / this.sliceCount), @@ -162,7 +162,7 @@ // Also tell the world where the mouse is hovering. var relX = event.pageX - _this.selector.offset().left; - var duration = _this._serializer.currentMedia().meta["dc:duration"]; + var duration = _this._serializer.getDuration(); var Time = ((relX / _this.width) * duration).toFixed(2); _this._Popcorn.trigger("IriSP.StackGraphWidget.mouseOver", Time); diff -r 9b8e68803f6f -r 7968346b9689 src/js/widgets/tweetsWidget.js --- a/src/js/widgets/tweetsWidget.js Tue Feb 21 17:26:51 2012 +0100 +++ b/src/js/widgets/tweetsWidget.js Wed Feb 29 18:13:14 2012 +0100 @@ -25,8 +25,8 @@ var imageMarkup = IriSP.templToHTML("user image", {src : img}); - if (typeof(annotation.meta["dc:source"].content) !== "undefined") { - var tweetContents = JSON.parse(annotation.meta["dc:source"].content); + if (typeof(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content) !== "undefined") { + var tweetContents = JSON.parse(IriSP.get_aliased(annotation.meta, ["dc:source", "source"]).content); var creator = tweetContents.user.screen_name; var real_name = tweetContents.user.name; diff -r 9b8e68803f6f -r 7968346b9689 test/integration/allocine_dossier_independant/allocine_test/exemple_cinecast.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/integration/allocine_dossier_independant/allocine_test/exemple_cinecast.json Wed Feb 29 18:13:14 2012 +0100 @@ -0,0 +1,97 @@ +{ + "format": "http://advene.org/ns/cinelab/", + "medias": [ + { + "id": "Au- nom-du-peuple-italien", + "meta": { + "actors": "Ugo Tognazzi, Vittorio Gassman, Ely Galleani", + "directors": "Dino Risi", + "duration": 120000, + "nationalities": "Italie", + "productionYear": "1971", + "synopsis": "Un petit juge ...", + "thumbnail": "http://xxxx.jpg", + "title": "Au nom du peuple italien", + "version": "VOST" + }, + "url": "http://allocine-f.akamaihd.net/nmedia/cinecast/inception.mp4" + }, + { + "id": "Avatar", + "meta": { + "duration": 120000, + "thumbnail": "http://xxxx.jpg", + "title": "Avatar" + }, + "url": "http://allocine-f.akamaihd.net/nmedia/cinecast/avatar.mp4" + } + ], + "annotation_types": [ + { + "id": "UserAnnotation", + "meta": { + "description": "Annotation made during the Cinecast Festival." + } + }, + { + "id": "MovieExtract", + "meta": { + "description": "Movie Extract." + } + } + ], + "annotations": [ + { + "begin": 0, + "content": { + "data": "Acte 1 Sc 1" + }, + "end": 10000, + "id": "1", + "media": "cinecast:Inception", + "meta": { + "created": "2012-02-15T00:00:00+01:00", + "creator": "VodKaster", + "thumbnail": "http://xxxx.jpg" + }, + "type": "cinecast:MovieExtract", + "tags": [ "cinecast:CultScene", "cinecast:CultMusic" ] + }, + { + "begin": 20000, + "content": { + "data": "Acte 2 Sc 2" + }, + "end": 30000, + "id": "2", + "media": "cinecast:Inception", + "meta": { + "created": "2012-02-15T00:00:00+01:00", + "creator": "VodKaster", + "thumbnail": "http://xxxx.jpg" + }, + "type": "cinecast:MovieExtract", + "tags": [ "cinecast:Funny", "cinecast:CultMusic" ] + } + ], + "tags": [ + { + "id": "Funny", + "meta": { + "description": "Tain que c'est dr!" + } + }, + { + "id": "CultScene", + "meta": { + "description": "La sc du sie !" + } + }, + { + "id": "CultMusic", + "meta": { + "description": "Pom pom pi dom !" + } + } + ] +} diff -r 9b8e68803f6f -r 7968346b9689 test/integration/allocine_dossier_independant/polemic-allocine.htm --- a/test/integration/allocine_dossier_independant/polemic-allocine.htm Tue Feb 21 17:26:51 2012 +0100 +++ b/test/integration/allocine_dossier_independant/polemic-allocine.htm Wed Feb 29 18:13:14 2012 +0100 @@ -15,13 +15,13 @@ - +