load subtitles/censor data in embeded player

This commit is contained in:
j 2012-02-17 14:27:21 +05:30
parent 81748afa2d
commit 7190568714
3 changed files with 90 additions and 40 deletions

View file

@ -15,18 +15,13 @@ Ox.load('UI', {
user: data.user.level == 'guest' ? Ox.clone(data.site.user) : data.user, user: data.user.level == 'guest' ? Ox.clone(data.site.user) : data.user,
ui: {}, ui: {},
clip: function(options) { clip: function(options) {
var that = Ox.Element(); var that = Ox.Element(),
pandora.api.get({id: options.item, keys: []}, function(result) { keys = [ 'duration', 'layers', 'parts', 'posterFrame', 'rightslevel', 'size', 'title', 'videoRatio' ];
var video = {}; pandora.user.ui.item = options.item;
pandora.site.video.resolutions.forEach(function(resolution) { pandora.api.get({id: options.item, keys: keys}, function(result) {
video[resolution] = Ox.range(result.data.parts).map(function(i) { var videoOptions = getVideoOptions(result.data);
var part = (i + 1),
prefix = pandora.site.site.videoprefix.replace('PART', part);
return prefix + '/' + options.item + '/'
+ resolution + 'p' + part + '.' + pandora.user.videoFormat;
});
});
that.append(pandora.player = Ox.VideoPlayer({ that.append(pandora.player = Ox.VideoPlayer({
censored: videoOptions.censored,
controlsBottom: ['play', 'volume', 'scale', 'timeline', 'position', 'settings'], controlsBottom: ['play', 'volume', 'scale', 'timeline', 'position', 'settings'],
enableFind: false, enableFind: false,
enableFullscreen: true, enableFullscreen: true,
@ -40,13 +35,14 @@ Ox.load('UI', {
out: options.out, out: options.out,
paused: options.paused, paused: options.paused,
position: options['in'], position: options['in'],
poster: '/' + options.item + '/' + '128p' + options['in'] +'.jpg', poster: '/' + options.item + '/' + '96p' + options['in'] +'.jpg',
resolution: pandora.user.ui.videoResolution, resolution: pandora.user.ui.videoResolution,
showMarkers: false, showMarkers: false,
showMilliseconds: 0, showMilliseconds: 0,
subtitles: videoOptions.subtitles,
timeline: '/' + options.item + '/' + 'timeline16p.png', timeline: '/' + options.item + '/' + 'timeline16p.png',
title: result.data.title, title: result.data.title,
video: video, video: videoOptions.video,
width: document.width width: document.width
}) })
.bindEvent({ .bindEvent({
@ -60,13 +56,13 @@ Ox.load('UI', {
Ox.UI.hideLoadingScreen(); Ox.UI.hideLoadingScreen();
function checkRange(data) { function checkRange(data) {
if(data.position < options['in'] if(data.position < options['in'] - 0.04
|| data.position > options.out) { || data.position > options.out) {
if(!pandora.player.options('paused')) { if(!pandora.player.options('paused')) {
pandora.player.togglePaused(); pandora.player.togglePaused();
} }
pandora.player.options({ pandora.player.options({
position: options['in'], position: options['in']
}); });
} }
} }
@ -77,6 +73,67 @@ Ox.load('UI', {
Ox.extend(pandora.user, { Ox.extend(pandora.user, {
videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats) videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats)
}); });
var options = parseQuery();
if (options.view == 'video') {
pandora.ui.info = pandora.clip(options)
.css({width: '100%', height: '100%'})
.appendTo(document.body);
}
}
});
function getVideoOptions(data) {
var canPlayClips = data.editable || pandora.site.capabilities.canPlayClips[pandora.user.level] >= data.rightslevel,
canPlayVideo = data.editable || pandora.site.capabilities.canPlayVideo[pandora.user.level] >= data.rightslevel,
options = {};
options.subtitles = data.layers.subtitles
? data.layers.subtitles.map(function(subtitle) {
return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value};
})
: [];
options.censored = canPlayVideo ? []
: canPlayClips ? (
options.subtitles.length
? Ox.merge(
options.subtitles.map(function(subtitle, i) {
return {
'in': i == 0 ? 0 : options.subtitles[i - 1].out,
out: subtitle['in']
};
}),
[{'in': Ox.last(options.subtitles).out, out: data.duration}]
)
: Ox.range(0, data.duration - 5, 60).map(function(position) {
return {
'in': position + 5,
out: Math.min(position + 60, data.duration)
};
})
)
: [{'in': 0, out: data.duration}];
options.video = {};
pandora.site.video.resolutions.forEach(function(resolution) {
options.video[resolution] = Ox.range(data.parts).map(function(i) {
var part = (i + 1),
prefix = pandora.site.site.videoprefix.replace('{part}', part);
return prefix + '/' + (data.item || pandora.user.ui.item) + '/'
+ resolution + 'p' + part + '.' + pandora.user.videoFormat;
});
});
options.layers = [];
pandora.site.layers.forEach(function(layer, i) {
options.layers[i] = Ox.extend({}, layer, {
items: data.layers[layer.id].map(function(annotation) {
annotation.duration = Math.abs(annotation.out - annotation['in']);
annotation.editable = annotation.editable
|| annotation.user == pandora.user.username
|| pandora.site.capabilities['canEditAnnotations'][pandora.user.level];
return annotation;
})
});
});
return options;
}
function parseQuery() { function parseQuery() {
var vars = window.location.search.length var vars = window.location.search.length
@ -99,12 +156,4 @@ Ox.load('UI', {
return Ox.extend({}, defaults, query); return Ox.extend({}, defaults, query);
} }
var options = parseQuery();
if (options.view == 'video') {
pandora.ui.info = pandora.clip(options)
.css({width: '100%', height: '100%'})
.appendTo(document.body);
}
}
});
}); });

View file

@ -3,7 +3,8 @@
pandora.ui.item = function() { pandora.ui.item = function() {
var that = Ox.Element(); var that = Ox.Element(),
videoOptions;
pandora.api.get({ pandora.api.get({
id: pandora.user.ui.item, id: pandora.user.ui.item,
@ -42,7 +43,7 @@ pandora.ui.item = function() {
if (['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1) { if (['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1) {
// fixme: layers have value, subtitles has text? // fixme: layers have value, subtitles has text?
var videoOptions = pandora.getVideoOptions(result.data); videoOptions = pandora.getVideoOptions(result.data);
} }
if (!result.data.rendered && [ if (!result.data.rendered && [

View file

@ -794,7 +794,7 @@ pandora.getVideoOptions = function(data) {
pandora.site.video.resolutions.forEach(function(resolution) { pandora.site.video.resolutions.forEach(function(resolution) {
options.video[resolution] = Ox.range(data.parts).map(function(i) { options.video[resolution] = Ox.range(data.parts).map(function(i) {
var part = (i + 1), var part = (i + 1),
prefix = pandora.site.site.videoprefix.replace('PART', part); // fixme: '{part}' would be more consistent prefix = pandora.site.site.videoprefix.replace('{part}', part);
return prefix + '/' + (data.item || pandora.user.ui.item) + '/' return prefix + '/' + (data.item || pandora.user.ui.item) + '/'
+ resolution + 'p' + part + '.' + pandora.user.videoFormat; + resolution + 'p' + part + '.' + pandora.user.videoFormat;
}); });