This commit is contained in:
rolux 2012-06-18 12:53:11 +02:00
parent 907f115b36
commit b733efa264

View file

@ -2,12 +2,17 @@
'use strict'; 'use strict';
pandora.ui.uploadDialog = function(data) { pandora.ui.uploadDialog = function(data) {
var content = Ox.Element().css({margin: '16px'}),
var actionButton,
cancelled = false, cancelled = false,
file,
closeButton, closeButton,
actionButton, file,
selectFile, selectFile,
$content = Ox.Element().css({margin: '16px'}),
$info = $('<div>').css({padding: '4px'})
.html('Please select the video file you want to upload.'),
$progress,
$status = $('<div>').css({padding: '4px', paddingTop: '8px'}),
that = Ox.Dialog({ that = Ox.Dialog({
buttons: [ buttons: [
closeButton = Ox.Button({ closeButton = Ox.Button({
@ -43,7 +48,7 @@ pandora.ui.uploadDialog = function(data) {
} }
}) })
], ],
content: content, content: $content,
height: 128, height: 128,
removeOnClose: true, removeOnClose: true,
width: 368, width: 368,
@ -57,20 +62,12 @@ pandora.ui.uploadDialog = function(data) {
} }
that.close(); that.close();
} }
}), });
$info= $('<div>').css({
padding: '4px'
})
.html('Please select the video file you want to upload.'),
$status = $('<div>').css({
padding: '4px',
paddingTop: '8px'
}),
$progress;
// FIXME: is this necessary?
pandora._status = $status; pandora._status = $status;
pandora._info = $info; pandora._info = $info;
if (typeof(Firefogg) == 'undefined') { if (Ox.isUndefined(Firefogg)) {
/* /*
selectFile = $('<input>') selectFile = $('<input>')
.attr({ .attr({
@ -98,28 +95,22 @@ pandora.ui.uploadDialog = function(data) {
} }
} }
}) })
.appendTo(content); .appendTo($content);
*/ */
actionButton.options({ actionButton.options({title: 'Close'});
title: 'Close' $info.css({paddingTop: '16px', paddingBottom: '16px'}).html(
}); 'Currently, video upload is only supported in '
$info.css({ + '<a target="_new" href="http://mozilla.org/firefox/">Firefox</a> with '
paddingTop: '16px', + '<a target="_new" href="http://firefogg.org/">Firefogg</a> installed.<br><br>'
paddingBottom: '16px' + 'Alternatively, you can use '
}).html( + '<a target="_new" href="https://wiki.0x2620.org/wiki/pandora_client">pandora_client</a>.'
'Sorry, right now upload is only supported in '
+ '<a target="_new" href="http://getfirefox.com">Firefox</a> '
+ 'with <a target="_new" href="http://firefogg.org/">Firefogg</a> installed.'
+ '<br><br>You can also use <a target="_new" href="https://wiki.0x2620.org/wiki/pandora_client">pandora_client</a> to upload videos.'
); );
} }
content.append($info); $content.append($info);
content.append($status); $content.append($status);
function aspectratio(ratio) { function aspectratio(ratio) {
var numerator, var denominator, numerator;
denominator;
ratio = ratio.split(':'); ratio = ratio.split(':');
numerator = ratio[0]; numerator = ratio[0];
if (ratio.length == 2) { if (ratio.length == 2) {
@ -133,10 +124,10 @@ pandora.ui.uploadDialog = function(data) {
denominator = 9; denominator = 9;
} }
return { return {
numerator: numerator,
denominator: denominator, denominator: denominator,
ratio: numerator + ':' + denominator, 'float': numerator / denominator,
'float': numerator/denominator numerator: numerator,
ratio: numerator + ':' + denominator
}; };
} }
@ -149,15 +140,16 @@ pandora.ui.uploadDialog = function(data) {
}); });
$status.html('').append($progress); $status.html('').append($progress);
} }
function encode() { function encode() {
var info = JSON.parse(pandora.firefogg.sourceInfo), var filename = pandora.firefogg.sourceFilename,
oshash = info.oshash, info = JSON.parse(pandora.firefogg.sourceInfo),
filename = pandora.firefogg.sourceFilename, item,
item; oshash = info.oshash;
resetProgress(); resetProgress();
pandora.api.addFile({ pandora.api.addFile({
id: oshash,
filename: filename, filename: filename,
id: oshash,
info: info info: info
}, function(result) { }, function(result) {
item = result.data.item; item = result.data.item;
@ -166,11 +158,7 @@ pandora.ui.uploadDialog = function(data) {
function(result, file) { function(result, file) {
result = JSON.parse(result); result = JSON.parse(result);
if (result.progress != 1) { if (result.progress != 1) {
if (cancelled) { $status.html(cancelled ? 'Encoding cancelled.' : 'Encoding failed.');
$status.html('Encoding cancelled.');
} else {
$status.html('Encoding failed.');
}
delete pandora.firefogg; delete pandora.firefogg;
return; return;
} }
@ -202,13 +190,12 @@ pandora.ui.uploadDialog = function(data) {
} }
function getEncodingOptions(info) { function getEncodingOptions(info) {
var format = pandora.site.video.formats[0], var bpp = 0.17,
resolution = Ox.max(pandora.site.video.resolutions),
bpp = 0.17,
fps,
dar, dar,
options = {}; format = pandora.site.video.formats[0],
fps,
options = {},
resolution = Ox.max(pandora.site.video.resolutions);
if (format == 'webm') { if (format == 'webm') {
options.videoCodec = 'vp8'; options.videoCodec = 'vp8';
options.audioCodec = 'vorbis'; options.audioCodec = 'vorbis';
@ -216,7 +203,6 @@ pandora.ui.uploadDialog = function(data) {
options.videoCodec = 'theora'; options.videoCodec = 'theora';
options.audioCodec = 'vorbis'; options.audioCodec = 'vorbis';
} }
if (resolution == 720) { if (resolution == 720) {
options.height = 720; options.height = 720;
options.samplerate = 48000; options.samplerate = 48000;
@ -264,20 +250,20 @@ pandora.ui.uploadDialog = function(data) {
fps = aspectratio(info.video[0].framerate).float; fps = aspectratio(info.video[0].framerate).float;
options.width = parseInt(dar.float * options.height, 10); options.width = parseInt(dar.float * options.height, 10);
options.width += options.width % 2; options.width += options.width % 2;
// interlaced hdv material is detected with double framerates // interlaced hdv material is detected with double framerates
if (fps == 50) { if (fps == 50) {
options.framerate = 25; options.framerate = 25;
} else if (fps == 60) { } else if (fps == 60) {
options.framerate = 30; options.framerate = 30;
} }
if (Math.abs(options.width/options.height - dar.float) < 0.02) { if (Math.abs(options.width/options.height - dar.float) < 0.02) {
options.aspect = options.width + ':' + options.height; options.aspect = options.width + ':' + options.height;
} else { } else {
options.aspect = dar.ratio; options.aspect = dar.ratio;
} }
options.videoBitrate = Math.round(options.height*options.width*fps*bpp/1000); options.videoBitrate = Math.round(
options.height * options.width * fps * bpp / 1000
);
options.denoise = true; options.denoise = true;
options.deinterlace = true; options.deinterlace = true;
} else { } else {
@ -293,9 +279,7 @@ pandora.ui.uploadDialog = function(data) {
delete options.audioQuality; delete options.audioQuality;
delete options.channels; delete options.channels;
} }
options.noUpscaling = true; options.noUpscaling = true;
if ( if (
(!info.video.length || ( (!info.video.length || (
info.video[0].codec == options.videoCodec info.video[0].codec == options.videoCodec
@ -309,12 +293,10 @@ pandora.ui.uploadDialog = function(data) {
} }
function formatInfo(info) { function formatInfo(info) {
var html = ''; var html = '<b>' + info.path + '</b><br>';
html += '<b>' + info.path + '</b>';
html += '<br />';
if (info.video && info.video.length > 0) { if (info.video && info.video.length > 0) {
var video = info.video[0]; var video = info.video[0];
html += video.width + 'x' + video.height + ' (' + video.codec + ')'; html += video.width + '×' + video.height + ' (' + video.codec + ')';
} }
if ( if (
info.video && info.video.length > 0 info.video && info.video.length > 0
@ -324,18 +306,11 @@ pandora.ui.uploadDialog = function(data) {
} }
if (info.audio && info.audio.length > 0) { if (info.audio && info.audio.length > 0) {
var audio = info.audio[0]; var audio = info.audio[0];
html += '' + { html += {1: 'mono', 2: 'stereo', 6: '5.1'}[audio.channels]
1: 'mono', + ' ' + audio.samplerate / 1000 + ' kHz (' + audio.codec + ')';
2: 'stereo',
6: '5.1'
}[audio.channels];
html += ' ' + audio.samplerate/1000 + ' kHz ';
html += '(' + audio.codec + ')';
} }
html += '<br />'; html += '<br>' + Ox.formatValue(info.size, 'B')
html += '' + Ox.formatValue(info.size, 'B'); + ' / ' + Ox.formatDuration(info.duration);
html += ' / ' + Ox.formatDuration(info.duration);
return html; return html;
} }
@ -356,13 +331,15 @@ pandora.ui.uploadDialog = function(data) {
keys: ['id', 'available'] keys: ['id', 'available']
}, function(result) { }, function(result) {
if ( if (
result.data.items.length === 0 || !result.data.items[0].available result.data.items.length === 0
|| !result.data.items[0].available
) { ) {
$info.html(formatInfo(info)); $info.html(formatInfo(info));
$status.html( $status.html(
options.passthrough options.passthrough
? 'Your video will be uploaded directly.' ? 'Your video will be uploaded directly.'
: 'Your video will be transcoded before upload.'); : 'Your video will be transcoded before upload.'
);
} else { } else {
pandora.api.find({ pandora.api.find({
query: { query: {
@ -385,4 +362,5 @@ pandora.ui.uploadDialog = function(data) {
} }
return that; return that;
}; };