summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2014-06-01 13:53:45 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2014-06-01 13:53:45 +0200
commitaa7e8ab9c17306ad8f11a5165b65f93d824f40e8 (patch)
treeb78873b123e87afcf28f271ba0a8a8491b697486
parentMerge pull request #642 from charlie89/fix-cookies (diff)
downloadpyload-aa7e8ab9c17306ad8f11a5165b65f93d824f40e8.tar.xz
implemented click captchas
-rw-r--r--pyload/interaction/InteractionTask.py36
-rw-r--r--pyload/web/app/scripts/views/input/clickInput.js43
-rw-r--r--pyload/web/app/scripts/views/input/inputLoader.js7
-rw-r--r--pyload/web/app/scripts/views/input/inputView.js5
-rw-r--r--pyload/web/app/scripts/views/queryModal.js16
-rwxr-xr-xpyload/web/app/templates/default/dialogs/interactionTask.html2
6 files changed, 88 insertions, 21 deletions
diff --git a/pyload/interaction/InteractionTask.py b/pyload/interaction/InteractionTask.py
index b404aa6ce..498d807c0 100644
--- a/pyload/interaction/InteractionTask.py
+++ b/pyload/interaction/InteractionTask.py
@@ -1,27 +1,25 @@
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- @author: RaNaN
-"""
+###############################################################################
+# Copyright(c) 2008-2014 pyLoad Team
+# http://www.pyload.org
+#
+# This file is part of pyLoad.
+# pyLoad is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# Subjected to the terms and conditions in LICENSE
+#
+# @author: RaNaN
+###############################################################################
from time import time
from pyload.Api import InteractionTask as BaseInteractionTask
from pyload.Api import Interaction, InputType, Input
-#noinspection PyUnresolvedReferences
+# noinspection PyUnresolvedReferences
class InteractionTask(BaseInteractionTask):
"""
General Interaction Task extends ITask defined by api with additional fields and methods.
@@ -61,6 +59,10 @@ class InteractionTask(BaseInteractionTask):
self.wait_until = 0
def convertResult(self, value):
+ if self.input.type == InputType.Click:
+ parts = value.split(',')
+ return int(parts[0]), int(parts[1])
+
#TODO: convert based on input/output
return value
diff --git a/pyload/web/app/scripts/views/input/clickInput.js b/pyload/web/app/scripts/views/input/clickInput.js
new file mode 100644
index 000000000..873c81ce7
--- /dev/null
+++ b/pyload/web/app/scripts/views/input/clickInput.js
@@ -0,0 +1,43 @@
+define(['jquery', 'backbone', 'underscore', 'helpers/gettext', './inputView'], function($, Backbone, _, gettext, inputView) {
+ 'use strict';
+
+ return inputView.extend({
+
+ tagName: 'input',
+ events: {
+ 'keyup': 'onChange',
+ 'focus': 'showTooltip',
+ 'focusout': 'hideTooltip'
+ },
+
+ renderInput: function() {
+ this.$el.attr('disabled', 'on');
+ this.$el.attr('type', 'text');
+ this.$el.attr('name', 'textInput');
+
+ if (this.default_value)
+ this.$el.attr('placeholder', this.default_value);
+ else
+ this.$el.attr('placeholder', gettext('Please click on the right position in the captcha.'));
+
+ if (this.value)
+ this.$el.val(this.value);
+
+ return this;
+ },
+
+ onClick: function(x,y) {
+ this.$el.val(x + "," + y);
+ this.onChange();
+ },
+
+ clear: function() {
+ this.$el.val('');
+ },
+
+ onChange: function(e) {
+ this.setVal(this.$el.val());
+ }
+
+ });
+}); \ No newline at end of file
diff --git a/pyload/web/app/scripts/views/input/inputLoader.js b/pyload/web/app/scripts/views/input/inputLoader.js
index 04d591d30..c28572c6c 100644
--- a/pyload/web/app/scripts/views/input/inputLoader.js
+++ b/pyload/web/app/scripts/views/input/inputLoader.js
@@ -1,8 +1,13 @@
-define(['./textInput'], function(textInput) {
+define(['utils/apitypes', './textInput', './clickInput'], function(Api, textInput, clickInput) {
'use strict';
// selects appropriate input element
return function(input) {
+ console.log('Select input', input);
+
+ if (input.type == Api.InputType.Click)
+ return clickInput;
+
return textInput;
};
}); \ No newline at end of file
diff --git a/pyload/web/app/scripts/views/input/inputView.js b/pyload/web/app/scripts/views/input/inputView.js
index 1860fcaf1..394e33aef 100644
--- a/pyload/web/app/scripts/views/input/inputView.js
+++ b/pyload/web/app/scripts/views/input/inputView.js
@@ -38,6 +38,11 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) {
return this;
},
+ // triggered by captcha clicks
+ onClick: function(x,y) {
+
+ },
+
renderInput: function() {
// Overwrite this
},
diff --git a/pyload/web/app/scripts/views/queryModal.js b/pyload/web/app/scripts/views/queryModal.js
index ce624814a..be66a47b4 100644
--- a/pyload/web/app/scripts/views/queryModal.js
+++ b/pyload/web/app/scripts/views/queryModal.js
@@ -1,9 +1,10 @@
-define(['jquery', 'underscore', 'app', 'views/abstract/modalView', './input/inputLoader', 'hbs!tpl/dialogs/interactionTask'],
- function($, _, App, modalView, load_input, template) {
+define(['jquery', 'underscore', 'app', 'utils/apitypes', 'views/abstract/modalView', './input/inputLoader', 'hbs!tpl/dialogs/interactionTask'],
+ function($, _, App, Api, modalView, load_input, template) {
'use strict';
return modalView.extend({
events: {
+ 'click #captchaImage': 'onClick',
'click .btn-success': 'submit',
'submit form': 'submit'
},
@@ -31,6 +32,9 @@ define(['jquery', 'underscore', 'app', 'views/abstract/modalView', './input/inpu
if (this.model.isCaptcha()) {
data.captcha = input[0];
data.type = input[1];
+
+ if (input.type == Api.InputType.Click)
+ data.click = true;
}
return data;
},
@@ -44,6 +48,14 @@ define(['jquery', 'underscore', 'app', 'views/abstract/modalView', './input/inpu
this.$('#inputField').append(this.input.render().el);
},
+ onClick: function(e) {
+ var el = $(e.target);
+ var posX = el.offset().left,
+ posY = el.offset().top;
+
+ this.input.onClick(Math.round(e.pageX - posX), Math.round(e.pageY - posY));
+ },
+
submit: function(e) {
e.stopPropagation();
// TODO: load next task
diff --git a/pyload/web/app/templates/default/dialogs/interactionTask.html b/pyload/web/app/templates/default/dialogs/interactionTask.html
index 722d43365..e1d649d1a 100755
--- a/pyload/web/app/templates/default/dialogs/interactionTask.html
+++ b/pyload/web/app/templates/default/dialogs/interactionTask.html
@@ -17,7 +17,7 @@
</label>
<div class="controls">
- <img id="captchaImage" src="data:image/{{ type }};base64,{{ captcha }}">
+ <img id="captchaImage" src="data:image/{{ type }};base64,{{ captcha }}" {{#if click}}style="cursor: crosshair;"{{/if}}>
</div>
</div>
<div class="control-group">