pandora_userscripts/playlist.js
2017-04-15 19:44:57 +02:00

156 lines
5.1 KiB
JavaScript

//open User->Preferences->Advanced->Run Script on Load and paste this script
(function() {
playlist([
[function() { info('A'); }, 10.000],
[function() { edit('ashok:Photomontage'); }, 100.000],
//[function() { info('A'); }, 30.000],
//[function() { play('B', 3); }, 10],
]);
//helper functions
function playlist(playlist) {
var current = 0;
pandora.$ui.home && pandora.$ui.home.fadeOutScreen();
clearTimeout(pandora.playlist);
next();
function next() {
if(current >= playlist.length) {
window.location.reload();
current = 0;
} else {
playlist[current][0]();
clearTimeout(pandora.playlist);
var duration = playlist[current][1];
if(Ox.isString(duration)) {
duration = Ox.parseDuration(duration);
}
pandora.playlist = setTimeout(next, Math.round(duration * 1000));
current += 1;
}
}
}
function sitePage(page) {
//if there is a player, pause it
pandora.$ui.player && pandora.$ui.player.options('paused', true);
//back to results view
pandora.UI.set({item: '', section: 'items'});
//open about page
pandora.UI.set({page: page});
}
function edit(edit, position) {
var resolution = [1920, 1080],
annotationsSize = resolution[0] - (resolution[1] * 4/3),
tvUI = {
annotationsSize: annotationsSize,
annotationsRange: 'position',
editView: 'annotations',
section: 'edits',
showAnnotations: true,
showTimeline: false, //fixme to enable recalculate aspect
showSidebar: false,
//videoLoop: true,
videoScale: 'fit'
};
position = position || 0;
pandora.UI.set(Ox.extend({
edit: edit
}, tvUI, 'edits.' + edit + '.position', position));
waitForPlayer(function(player) {
player.options({
paused: false,
position: position
});
});
}
function editor(item, start) {
playItem(item, 'editor', start);
}
function info(item) {
pandora.UI.set({section: 'items'});
pandora.UI.set({page: ''});
pandora.UI.set({itemView: 'info'});
pandora.UI.set({item: item});
}
function play(item, position, layers) {
playItem(item, 'player', position, layers);
}
function timeline(item, position, layers) {
playItem(item, 'timeline', position, layers);
}
function playItem(item, view, position, layers) {
pandora.UI.set({section: 'items'});
showLayers(layers);
position = position || 0;
if(Ox.isString(position)) {
position = Ox.parseDuration(position);
}
pandora.UI.set({page: ''});
pandora.UI.set('videoPoints.' + item, {
'annotation': '',
'in': position,
out: position,
position: position
});
if(item != pandora.user.ui.item || pandora.user.ui.itemView != view) {
delete pandora.$ui[view];
pandora.UI.set({itemView: view});
pandora.UI.set({item: item});
}
startPlayback();
function startPlayback() {
if(pandora.$ui[view]) {
pandora.$ui[view].options({paused: false});
} else {
setTimeout(startPlayback, 500);
}
}
}
function find(query, view) {
view = view || 'grid';
pandora.UI.set({item: '', page: '', listView: view, section: 'items'});
pandora.$ui.findInput.value(query);
pandora.UI.set({find: {conditions: [{key: '*', value: query, operator: '='}], operator: '&'}});
}
function showLayers(layers) {
layers = layers || Object.keys(pandora.site.user.ui.showLayers).filter(function(layer) {
return pandora.site.user.ui.showLayers[layer];
});
pandora.UI.set('showLayers', Ox.map(pandora.site.user.ui.showLayers, function(value, layer) {
return layers.indexOf(layer) > -1;
}));
}
function waitForPlayer(callback) {
var $player, player;
if (pandora.$ui.editPanel) {
$player = $('.OxVideoPlayer').not('.OxBar');
if($player.data('oxid') && Ox.$elements[$player.data('oxid')]) {
player = Ox.$elements[$player.data('oxid')];
}
}
if (player) {
setTimeout(function() {
callback(player, $player);
}, 250);
} else {
setTimeout(function() { waitForPlayer(callback); }, 250);
}
}
function openDocument(id) {
//if there is a player, pause it
pandora.$ui.player && pandora.$ui.player.options('paused', true);
pandora.URL.push('/documents/' + id);
}
function closeDocument() {
pandora.$ui.documentDialog.close();
}
})();