:- module(annotate, [ http_yaz_annotate/1 ]). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_parameters)). :- use_module(library(http/html_write)). :- use_module(library(http/http_path)). :- use_module(library(http/html_head)). :- use_module(library(http/http_json)). :- use_module(library(http/json)). :- use_module(library(http/http_session)). :- use_module(library(semweb/rdf_db)). :- use_module(user(user_db)). :- use_module(library(yaz_util)). :- use_module(library(user_process)). :- use_module(library(video_annotation)). :- use_module(components(yaz_page)). :- http_handler(yaz(annotate), http_yaz_annotate, []). %% http_yaz_annotate(+Request) % % Emit the tags for a video. % % @TBD show the tags that are already added. % By same user, by all? http_yaz_annotate(Request) :- ensure_logged_on(User0), user_property(User0, url(User)), http_parameters(Request, [ video(Video, [optional(true), description('URL of a video on webpage')]), title(Title, [optional(true), description('Title of the webpage')]) ]), ( (var(Video);var(Title)) -> html_annotate_form(Video, Title) ; create_user_process(User, [rdf:type=pprime:'Annotation', opmv:used=Video ], _Process), add_resource_properties(Video, [dc:title=Title]), html_annotate_page(Video, Title, User) ). %% html_annotate_form(?Video, ?Title) % % Emit an html page with a form to submit a page for annotation. html_annotate_form(Video0, Title0) :- var_to_atom(Video0, Video), var_to_atom(Title0, Title), reply_html_page(yaz, [ title(['YAZ - annotate']) ], [ \html_requires(css('annotate.css')), h2('Provide the URL of a page containing a Video'), form([div(class(inputline), [div(class(label), title), input([type(text), size(60), name(title), value(Title)])]), div(class(inputline), [div(class(label), 'video URL'), input([type(text), size(60), name(video), value(Video)])]), div(class(inputline), input([type(submit), value(annotate)])) ]) ]). var_to_atom(X, X) :- nonvar(X). var_to_atom(_, ''). %% html_annotate_form(+Video, +Title, +User) % % Emit an html page with video annotation funtionality. % html_annotate_page(Video, Title, _User) :- reply_html_page(yaz, [ title(['YAZ - annotate ', Title]) ], [ \html_requires(css('annotate.css')), h2(class('video-title'), Title), div(class('videobox'), [ div(id(video), []), div([id(annotate), style('margin-left:500px')], [ h4('Which people, organisations, locations and events occur in the video?'), input([id(search), size(40)]) ]) ]), ul(id(tags), []), script(type('text/javascript'), \jquery_annotate_script(Video)) ]). jquery_annotate_script(Video) --> { http_absolute_location(js('videoplayer/'), FilePath, []), http_location_by_id(http_create_video_annotation, CreateAnnotation) }, html_requires('http://freebaselibs.com/static/suggest/1.2.1/suggest.min.css'), html_requires(js('jquery/css/flick/jquery-ui-1.8.4.custom.css')), html_requires(js('jquery/jquery-1.4.2.min.js')), html_requires(js('jquery/jquery-ui-1.8.4.custom.js')), html_requires(js('videoplayer/jquery-videoplayer.js')), html_requires(js('videoplayer/tagbar.js')), html_requires('http://freebaselibs.com/static/suggest/1.2.1/suggest.min.js'), html_requires(js('videoplayer/swfobject.js')), html_requires(js('json2.js')), html(\[ '$("#video").videoplayer({ width: 480, height: 320, filepath:"',FilePath,'", src:"',Video,'" });\n', '$("#search").suggest({ "suggest_new": "Suggest a new term" })\n', '.bind("fb-select", function(e, data) { tagentry(data); })\n', '.bind("fb-select-new", function(e, label) { tagentry({name:label}); });\n', '$("#search").keypress(function(e) { $("#video").videoplayer("pause"); });\n', 'function tagentry(data) { var video = "', Video, '", startTime = $("#video").videoplayer("getTime"), tagtype = data["n:type"] ? data["n:type"].id : null, typelabel = data["n:type"] ? data["n:type"].name : null;\n', ' $.ajax({ url: "',CreateAnnotation,'", dataType: "json", data: {\n', ' value: JSON.stringify({value:data.id, type:"uri"}), //label: data.name, //type: tagtype, //type_label: typelabel, video: video, time: startTime*1000 },\n', ' success: addTagBar }); };\n', '$("#tags").sortable();\n', 'function addTagBar(data) {\n', ' var startTime = Math.round(data.time/1000);\n', ' $("#search").val("");\n', ' $("#tags") .prepend($("
  • ")\n', ' .tagbar({ label: data.label, start: startTime, end: startTime+10, max: $("#video").videoplayer("getDuration") }));\n', '};\n' ]).