access callback, only one frame/video extraction thread. make sure all frames are extracted before returning them
This commit is contained in:
parent
6bdeb5ef85
commit
0af4304e88
4 changed files with 39 additions and 14 deletions
|
@ -90,6 +90,7 @@ def hash_prefix(h):
|
|||
return [h[:2], h[2:4], h[4:6], h[6:]]
|
||||
|
||||
def run_command(cmd, timeout=25):
|
||||
#print cmd
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
while timeout > 0:
|
||||
time.sleep(0.2)
|
||||
|
@ -152,6 +153,7 @@ def extract_frame(video, target, position):
|
|||
framedir = tempfile.mkdtemp()
|
||||
os.chdir(framedir)
|
||||
cmd = ['mplayer', '-noautosub', video, '-ss', str(position), '-frames', '2', '-vo', 'png:z=9', '-ao', 'null']
|
||||
print cmd
|
||||
r = run_command(cmd)
|
||||
images = glob('%s/*.png' % framedir)
|
||||
if images:
|
||||
|
@ -292,7 +294,7 @@ class Database(object):
|
|||
def __init__(self, db_conn):
|
||||
|
||||
self.extract = Queue.Queue()
|
||||
for i in range(2):
|
||||
#for i in range(2):
|
||||
t = ExtractThread(self)
|
||||
t.setDaemon(True)
|
||||
t.start()
|
||||
|
@ -459,7 +461,6 @@ class Database(object):
|
|||
self.derivative(oshash, frame_name, STATUS_FAILED)
|
||||
elif name.endswith('.webm'):
|
||||
profile = name[:-5]
|
||||
print 'now lets go, are we having fun?'
|
||||
self.derivative(oshash, name, STATUS_EXTRACTING)
|
||||
if extract_video(f['path'], derivative['path'], profile, f['info']):
|
||||
self.derivative(oshash, name, STATUS_AVAILABLE)
|
||||
|
@ -732,21 +733,30 @@ class OxControl(Resource):
|
|||
derivative = self.db.derivative(oshash, name)
|
||||
if derivative['status'] == STATUS_FAILED and retry:
|
||||
derivative = self.db.derivative(oshash, name, STATUS_NEW)
|
||||
response['status'] = {
|
||||
_STATUS = {
|
||||
STATUS_NEW: 'extracting',
|
||||
STATUS_EXTRACTING: 'extracting',
|
||||
STATUS_AVAILABLE: 'available',
|
||||
STATUS_FAILED: 'failed',
|
||||
}.get(derivative['status'], 'extracting')
|
||||
}
|
||||
response['status'] = _STATUS.get(derivative['status'], 'extracting')
|
||||
if derivative['status'] == STATUS_NEW:
|
||||
self.db.extract.put((oshash, name))
|
||||
|
||||
if derivative['status'] == STATUS_EXTRACTING:
|
||||
print "queue", self.db.extract.qsize()
|
||||
response['progress'] = enc_status.get(oshash, 0)
|
||||
|
||||
files = [f['path'] for f in self.db.derivatives(oshash)]
|
||||
if media == 'frames':
|
||||
status = derivative['status']
|
||||
for f in self.db.derivatives(oshash):
|
||||
if f['path'].endswith('.png'):
|
||||
status = min(status, f['status'])
|
||||
if status == derivative['status']:
|
||||
response['frames'] = filter(lambda f: f.endswith('.png'), files)
|
||||
else:
|
||||
response['status'] = _STATUS.get(status, 'extracting')
|
||||
else:
|
||||
response['video'] = filter(lambda f: f.endswith(media), files)
|
||||
if response['video']: response['video'] = response['video'][0]
|
||||
|
|
|
@ -129,8 +129,7 @@ OxFF.prototype = {
|
|||
//nsIOxFF
|
||||
version: "bzr",
|
||||
|
||||
access: function(request) {
|
||||
if (typeof(request) == 'undefined') request = false;
|
||||
access: function(callback) {
|
||||
var _this = this;
|
||||
|
||||
var conn = oxff.getDB();
|
||||
|
@ -144,22 +143,28 @@ OxFF.prototype = {
|
|||
}
|
||||
q.finalize();
|
||||
|
||||
if (request && !this._access) {
|
||||
if (callback && !this._access) {
|
||||
var windowMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
var nsWindow = windowMediator.getMostRecentWindow("navigator:browser");
|
||||
var box = nsWindow.gBrowser.getNotificationBox();
|
||||
var buttons = [{
|
||||
label : "Allow",
|
||||
accessKey : "A",
|
||||
callback : function() { _this.permitAccess(); }
|
||||
callback : function() { _this.permitAccess();
|
||||
if(callback) callback.callback(true);
|
||||
}
|
||||
},
|
||||
{
|
||||
label : "Deny",
|
||||
accessKey : "D",
|
||||
callback : function() { _this.denyAccess(); }
|
||||
callback : function() { _this.denyAccess();
|
||||
if(callback) callback.callback(false);
|
||||
}
|
||||
}];
|
||||
box.appendNotification("Do you wnat to allow "+_this._site+" to manage archvies on your computer",
|
||||
'oxff_permission' , null , box.PRIORITY_INFO_MEDIUM , buttons);
|
||||
} else if(callback) {
|
||||
callback.callback(this._access);
|
||||
}
|
||||
return this._access;
|
||||
},
|
||||
|
@ -225,6 +230,7 @@ OxFF.prototype = {
|
|||
var formData = options.data;
|
||||
else
|
||||
var formData = {};
|
||||
|
||||
var url = options.url;
|
||||
|
||||
if (callback)
|
||||
|
|
Binary file not shown.
|
@ -9,6 +9,15 @@ interface oxICallback : nsISupports
|
|||
void callback(in AString result);
|
||||
};
|
||||
|
||||
[function, scriptable, uuid(70015be1-2620-4682-ba3c-8024e7cb41ac)]
|
||||
interface oxIBooleanCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* @param result boolean
|
||||
*/
|
||||
void callback(in boolean result);
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(333280ed-2620-46ed-916d-b9c29e84d9ba)]
|
||||
interface nsIOxFF : nsISupports
|
||||
|
@ -16,7 +25,7 @@ interface nsIOxFF : nsISupports
|
|||
readonly attribute string version;
|
||||
|
||||
boolean login(in AString user);
|
||||
boolean access([optional] in boolean request);
|
||||
boolean access([optional] in oxIBooleanCallback callback);
|
||||
boolean logout();
|
||||
|
||||
string volumes(in oxICallback callback);
|
||||
|
|
Loading…
Reference in a new issue