160 lines
7.3 KiB
JavaScript
Executable file
160 lines
7.3 KiB
JavaScript
Executable file
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
|
'use strict';
|
|
|
|
Ox.load('UI', {
|
|
debug: false,
|
|
hideScreen: false,
|
|
loadImages: true,
|
|
showScreen: true,
|
|
theme: 'modern'
|
|
}, function() {
|
|
window.pandora = new Ox.App({url: '/api/'}).bindEvent({
|
|
load: function(data) {
|
|
Ox.extend(pandora, {
|
|
site: data.site,
|
|
user: data.user.level == 'guest' ? Ox.clone(data.site.user) : data.user,
|
|
ui: {},
|
|
clip: function(options) {
|
|
var that = Ox.Element(),
|
|
keys = [ 'cuts', 'director', 'duration', 'layers', 'parts', 'posterFrame', 'rendered', 'rightslevel', 'size', 'title', 'videoRatio', 'year'];
|
|
pandora.api.get({id: options.item, keys: keys}, function(result) {
|
|
var video = {},
|
|
videoOptions = getVideoOptions(result.data);
|
|
Ox.print(videoOptions);
|
|
Ox.print('/' + options.item + '/' + 'timeline16p.png');
|
|
that.append(pandora.player = Ox.VideoPlayer({
|
|
censored: videoOptions.censored,
|
|
controlsBottom: ['play', 'volume', 'scale', 'timeline', 'position', 'settings'],
|
|
enableFind: false,
|
|
enableFullscreen: true,
|
|
enableKeyboard: true,
|
|
enableMouse: true,
|
|
enableTimeline: true,
|
|
enableVolume: true,
|
|
externalControls: false,
|
|
height: document.height,
|
|
'in': options['in'],
|
|
out: options.out,
|
|
paused: options.paused,
|
|
position: options['in'],
|
|
poster: '/' + options.item + '/' + '96p' + options['in'] +'.jpg',
|
|
resolution: pandora.user.ui.videoResolution,
|
|
showMarkers: false,
|
|
showMilliseconds: 0,
|
|
subtitles: videoOptions.subtitles,
|
|
timeline: '/' + options.item + '/' + 'timeline16p.png',
|
|
title: result.data.title,
|
|
video: videoOptions.video,
|
|
width: document.width
|
|
})
|
|
.bindEvent({
|
|
playing: checkRange,
|
|
position: checkRange,
|
|
resolution: function(data) {
|
|
pandora.api.setUI({'videoResolution': data.resolution});
|
|
},
|
|
})
|
|
);
|
|
Ox.UI.hideLoadingScreen();
|
|
|
|
function checkRange(data) {
|
|
if(data.position < options['in']
|
|
|| data.position > options.out) {
|
|
if(!pandora.player.options('paused')) {
|
|
pandora.player.togglePaused();
|
|
}
|
|
pandora.player.options({
|
|
position: options['in'],
|
|
});
|
|
}
|
|
}
|
|
});
|
|
return that;
|
|
}
|
|
});
|
|
Ox.extend(pandora.user, {
|
|
videoFormat: Ox.UI.getVideoFormat(pandora.site.video.formats)
|
|
});
|
|
|
|
function parseQuery() {
|
|
var vars = window.location.search.length
|
|
? window.location.search.substring(1).split('&')
|
|
: [],
|
|
query = {
|
|
item: window.location.pathname.substring(1).split('/')[0]
|
|
},
|
|
defaults = {
|
|
view: 'video',
|
|
'in': 0,
|
|
out: 10,
|
|
paused: true,
|
|
item: ''
|
|
};
|
|
vars.forEach(function(v) {
|
|
v= v.split('=');
|
|
query[v[0]] = decodeURIComponent(v[1]);
|
|
});
|
|
|
|
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);
|
|
}
|
|
}
|
|
});
|
|
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;
|
|
}
|
|
});
|