use firefogg/utils.jsm instead of local copy
This commit is contained in:
parent
a3e3de8c99
commit
6bdeb5ef85
3 changed files with 17 additions and 216 deletions
|
@ -13,8 +13,9 @@ const Ci = Components.interfaces;
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
Components.utils.import("resource://firefogg/uploader.jsm");
|
Components.utils.import("resource://firefogg/uploader.jsm");
|
||||||
|
Components.utils.import("resource://firefogg/encoder.jsm");
|
||||||
|
Components.utils.import("resource://firefogg/utils.jsm");
|
||||||
|
|
||||||
Components.utils.import("resource://ox/utils.jsm");
|
|
||||||
Components.utils.import("resource://ox/oxff.jsm");
|
Components.utils.import("resource://ox/oxff.jsm");
|
||||||
|
|
||||||
var OxFFFactory =
|
var OxFFFactory =
|
||||||
|
@ -44,30 +45,13 @@ function OxFF() {
|
||||||
this.access();
|
this.access();
|
||||||
|
|
||||||
if (!oxff.get('username')) {
|
if (!oxff.get('username')) {
|
||||||
oxff.set('username', ox.makeRandomString(8));
|
oxff.set('username', utils.makeRandomString(8));
|
||||||
oxff.set('password', ox.makeRandomString(8));
|
oxff.set('password', utils.makeRandomString(8));
|
||||||
}
|
}
|
||||||
this.authkey = oxff.get('username');
|
this.authkey = oxff.get('username');
|
||||||
this.password = oxff.get('password');
|
this.password = oxff.get('password');
|
||||||
|
|
||||||
try {
|
this._ffmpeg2theora = ffenc.bin('ffmpeg2theora');
|
||||||
//FF3.6 fallback
|
|
||||||
var em = Cc["@mozilla.org/extensions/manager;1"]
|
|
||||||
.getService(Ci.nsIExtensionManager);
|
|
||||||
var f = em.getInstallLocation('firefogg@firefogg.org').getItemFile('firefogg@firefogg.org', 'ffmpeg2theora');
|
|
||||||
_this._ffmpeg2theora = f.path;
|
|
||||||
} catch(e) {
|
|
||||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
||||||
AddonManager.getAddonByID('firefogg@firefogg.org', function(addon) {
|
|
||||||
if (addon.hasResource('bin')) {
|
|
||||||
var resource = addon.getResourceURI('bin');
|
|
||||||
var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile);
|
|
||||||
file.append('ffmpeg2theora');
|
|
||||||
_this._ffmpeg2theora = file.path;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OxFF.prototype = {
|
OxFF.prototype = {
|
||||||
|
@ -195,7 +179,7 @@ OxFF.prototype = {
|
||||||
var base = this.base; //later base can not be a public property
|
var base = this.base; //later base can not be a public property
|
||||||
var url = base + action;
|
var url = base + action;
|
||||||
|
|
||||||
ox.request({
|
utils.request({
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
load: function(e) {
|
load: function(e) {
|
||||||
|
@ -206,7 +190,7 @@ OxFF.prototype = {
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
_this.startDaemon();
|
_this.startDaemon();
|
||||||
ox.setTimeout(function() { _this.api(action, data, callback); }, 1000);
|
utils.setTimeout(function() { _this.api(action, data, callback); }, 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -249,7 +233,7 @@ OxFF.prototype = {
|
||||||
progress = progress.callback;
|
progress = progress.callback;
|
||||||
|
|
||||||
if (options.action == 'frames') {
|
if (options.action == 'frames') {
|
||||||
var timer = ox.setInterval(function() {
|
var timer = utils.setInterval(function() {
|
||||||
_this.api('extract', {oshash: options.oshash, media: 'frames'}, function(result) {
|
_this.api('extract', {oshash: options.oshash, media: 'frames'}, function(result) {
|
||||||
var data = JSON.parse(result);
|
var data = JSON.parse(result);
|
||||||
if (data.status == 'extracting') {
|
if (data.status == 'extracting') {
|
||||||
|
@ -266,7 +250,7 @@ OxFF.prototype = {
|
||||||
f.initWithPath(data.frames[i]);
|
f.initWithPath(data.frames[i]);
|
||||||
formData.frame.push(f);
|
formData.frame.push(f);
|
||||||
}
|
}
|
||||||
ox.request({
|
utils.request({
|
||||||
url: url,
|
url: url,
|
||||||
data: formData,
|
data: formData,
|
||||||
load: function(e) {
|
load: function(e) {
|
||||||
|
@ -294,7 +278,7 @@ OxFF.prototype = {
|
||||||
formData.file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile)
|
formData.file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile)
|
||||||
formData.file.initWithPath(path);
|
formData.file.initWithPath(path);
|
||||||
if (formData.file.exists()) { //FIXME: should check if more than one file with oshash is known
|
if (formData.file.exists()) { //FIXME: should check if more than one file with oshash is known
|
||||||
ox.request({
|
utils.request({
|
||||||
url: url,
|
url: url,
|
||||||
data: formData,
|
data: formData,
|
||||||
load: function(e) {
|
load: function(e) {
|
||||||
|
@ -310,7 +294,7 @@ OxFF.prototype = {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (options.action == 'video') {
|
} else if (options.action == 'video') {
|
||||||
var timer = ox.setInterval(function() {
|
var timer = utils.setInterval(function() {
|
||||||
_this.api('extract', {oshash: options.oshash, media: options.profile}, function(result) {
|
_this.api('extract', {oshash: options.oshash, media: options.profile}, function(result) {
|
||||||
var data = JSON.parse(result);
|
var data = JSON.parse(result);
|
||||||
if (data.status == 'extracting') {
|
if (data.status == 'extracting') {
|
||||||
|
@ -427,25 +411,10 @@ OxFF.prototype = {
|
||||||
var args = [oxff.getDBFile().path, _this._ffmpeg2theora];
|
var args = [oxff.getDBFile().path, _this._ffmpeg2theora];
|
||||||
_this._daemon.runw(false, args, args.length);
|
_this._daemon.runw(false, args, args.length);
|
||||||
}
|
}
|
||||||
|
var file = __LOCATION__.parent.parent.QueryInterface(Ci.nsILocalFile);
|
||||||
try {
|
file.appendRelativePath('bin');
|
||||||
//FF3.6 fallback
|
file.appendRelativePath(daemon);
|
||||||
var em = Cc["@mozilla.org/extensions/manager;1"]
|
|
||||||
.getService(Ci.nsIExtensionManager);
|
|
||||||
var file = em.getInstallLocation(this.extensionID).getItemFile(this.extensionID, daemon);
|
|
||||||
runDaemon(file);
|
runDaemon(file);
|
||||||
} catch(e) {
|
|
||||||
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
|
||||||
AddonManager.getAddonByID(this.extensionID, function(addon) {
|
|
||||||
if (addon.hasResource('bin')) {
|
|
||||||
var resource = addon.getResourceURI('bin');
|
|
||||||
var file = resource.QueryInterface(Ci.nsIFileURL).file.QueryInterface(Ci.nsILocalFile);
|
|
||||||
file.append(daemon);
|
|
||||||
runDaemon(file);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ let EXPORTED_SYMBOLS = [ "oxff" ];
|
||||||
const Cc = Components.classes;
|
const Cc = Components.classes;
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
|
||||||
Components.utils.import("resource://ox/utils.jsm");
|
Components.utils.import("resource://firefogg/encoder.jsm");
|
||||||
|
|
||||||
let oxff = {
|
let oxff = {
|
||||||
getDBFile: function() {
|
getDBFile: function() {
|
||||||
|
@ -59,7 +59,7 @@ let oxff = {
|
||||||
var path = q.row.path;
|
var path = q.row.path;
|
||||||
q.finalize();
|
q.finalize();
|
||||||
|
|
||||||
ox.subprocess(command, options, callback);
|
ffenc.subprocess(command, options, callback);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,168 +0,0 @@
|
||||||
// -*- coding: utf-8 -*-
|
|
||||||
// vi:si:et:sw=4:sts=4:ts=4:ft=js
|
|
||||||
|
|
||||||
let EXPORTED_SYMBOLS = [ "ox" ];
|
|
||||||
|
|
||||||
const Cc = Components.classes;
|
|
||||||
const Ci = Components.interfaces;
|
|
||||||
|
|
||||||
let ox = {
|
|
||||||
setTimeout: function(callback, timeout) {
|
|
||||||
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
||||||
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
||||||
},
|
|
||||||
setInterval: function(callback, timeout) {
|
|
||||||
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
||||||
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_REPEATING_SLACK);
|
|
||||||
return timer;
|
|
||||||
},
|
|
||||||
glob: function (path) {
|
|
||||||
/*
|
|
||||||
return array of all files(in all subdirectories) for given directory
|
|
||||||
*/
|
|
||||||
var directory = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
|
|
||||||
directory.initWithPath(path);
|
|
||||||
var entries = directory.directoryEntries;
|
|
||||||
var array = [];
|
|
||||||
while(entries.hasMoreElements()) {
|
|
||||||
var entry = entries.getNext();
|
|
||||||
entry.QueryInterface(Components.interfaces.nsIFile);
|
|
||||||
if(entry.isDirectory()) {
|
|
||||||
var sub = this.glob(entry.path);
|
|
||||||
for(i in sub) {
|
|
||||||
array.push(sub[i]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
array.push(entry.path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
},
|
|
||||||
makeRandomString: function(len) {
|
|
||||||
var s = "";
|
|
||||||
var table = [
|
|
||||||
'a','b','c','d','e','f','g','h','i','j',
|
|
||||||
'k','l','m','n','o','p','q','r','s','t',
|
|
||||||
'u','v','w','x','y','z','0','1','2','3',
|
|
||||||
'4','5','6','7','8','9'
|
|
||||||
];
|
|
||||||
for(var i=0;i<len;i++) {
|
|
||||||
s += table[parseInt(Math.random() * table.length)];
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
},
|
|
||||||
request: function(options) {
|
|
||||||
var url = options.url,
|
|
||||||
data = options.data,
|
|
||||||
boundary = "--------XX" + Math.random();
|
|
||||||
|
|
||||||
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
||||||
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
|
||||||
converter.charset = "UTF-8";
|
|
||||||
|
|
||||||
var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
||||||
.createInstance(Ci.nsIXMLHttpRequest);
|
|
||||||
|
|
||||||
var multiStream = Cc["@mozilla.org/io/multiplex-input-stream;1"]
|
|
||||||
.createInstance(Ci.nsIMultiplexInputStream);
|
|
||||||
|
|
||||||
if(options.progress)
|
|
||||||
req.upload.addEventListener("progress", options.progress, false);
|
|
||||||
if(options.load)
|
|
||||||
req.addEventListener("load", options.load, false);
|
|
||||||
if(options.error)
|
|
||||||
req.addEventListener("error", options.error, false);
|
|
||||||
if(options.abort)
|
|
||||||
req.addEventListener("abort", options.abort, false);
|
|
||||||
|
|
||||||
function appendData(key, value) {
|
|
||||||
if(value.leafName) {
|
|
||||||
try {
|
|
||||||
var mimeService = Cc["@mozilla.org/mime;1"].createInstance(Ci.nsIMIMEService);
|
|
||||||
var mimeType = mimeService.getTypeFromFile(value);
|
|
||||||
}
|
|
||||||
catch(e) {
|
|
||||||
var mimeType = "application/octet-stream";
|
|
||||||
}
|
|
||||||
|
|
||||||
var filename = value.leafName;
|
|
||||||
var formData = "--" + boundary + "\r\n" +
|
|
||||||
"Content-Disposition: form-data; name=\"" + key +
|
|
||||||
"\"; filename=\"" + filename + "\"\r\n" +
|
|
||||||
"Content-type: " + mimeType + "\r\n\r\n";
|
|
||||||
var formData = converter.convertToInputStream(formData);
|
|
||||||
multiStream.appendStream(formData);
|
|
||||||
|
|
||||||
var fileStream = Cc["@mozilla.org/network/file-input-stream;1"]
|
|
||||||
.createInstance(Ci.nsIFileInputStream);
|
|
||||||
fileStream.init(value, 0x01, 0644, 0x04); // file is an nsIFile instance
|
|
||||||
multiStream.appendStream(fileStream);
|
|
||||||
|
|
||||||
formData = "\r\n";
|
|
||||||
formData = converter.convertToInputStream(formData);
|
|
||||||
multiStream.appendStream(formData);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
var formData = "--" + boundary + "\r\n" +
|
|
||||||
"Content-Disposition: form-data; name=\""+key+"\"\r\n\r\n" +
|
|
||||||
value + "\r\n";
|
|
||||||
formData = converter.convertToInputStream(formData);
|
|
||||||
multiStream.appendStream(formData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (data) {
|
|
||||||
for(key in data) {
|
|
||||||
if (typeof(data[key]) == 'object' && data[key].length>0) {
|
|
||||||
for(i in data[key])
|
|
||||||
appendData(key, data[key][i]);
|
|
||||||
} else if (data[key]) {
|
|
||||||
appendData(key, data[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var formData = "--" + boundary + "--\r\n";
|
|
||||||
formData = converter.convertToInputStream(formData);
|
|
||||||
multiStream.appendStream(formData);
|
|
||||||
|
|
||||||
req.open("POST", url);
|
|
||||||
req.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary);
|
|
||||||
req.setRequestHeader("Content-length", multiStream.available());
|
|
||||||
req.send(multiStream);
|
|
||||||
return req;
|
|
||||||
},
|
|
||||||
subprocess: function(command, options, callback) {
|
|
||||||
if(!this.ipcService) {
|
|
||||||
this.ipcService = Cc["@mozilla.org/process/ipc-service;1"]
|
|
||||||
.getService().QueryInterface(Ci.nsIIPCService);
|
|
||||||
}
|
|
||||||
var cmd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
|
|
||||||
cmd.initWithPath(command);
|
|
||||||
|
|
||||||
if(command.indexOf(".exe")==-1 &&
|
|
||||||
command.substr(0, 15) != "/usr/local/bin/" &&
|
|
||||||
command.substr(0, 9) != "/usr/bin/") {
|
|
||||||
cmd.permissions = 0755;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof(callback) == 'function') {
|
|
||||||
var thread = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager)
|
|
||||||
.newThread(0);
|
|
||||||
var backgroundTask = {
|
|
||||||
run: function() {
|
|
||||||
var result = that.ipcService.run(cmd, options, options.length);
|
|
||||||
callback(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
thread.dispatch(backgroundTask, thread.DISPATCH_NORMAL);
|
|
||||||
} else { //no callback, call subprocess blocking, will only return once done
|
|
||||||
/*
|
|
||||||
dump('\ncmd: ');
|
|
||||||
dump(cmd.path)
|
|
||||||
dump('\n');
|
|
||||||
dump(options)
|
|
||||||
*/
|
|
||||||
return this.ipcService.run(cmd, options, options.length);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
Loading…
Reference in a new issue