summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/hooks')
-rw-r--r--module/plugins/hooks/ClickAndLoad.py82
-rw-r--r--module/plugins/hooks/HotFolder.py35
-rw-r--r--module/plugins/hooks/XFileSharingPro.py4
3 files changed, 46 insertions, 75 deletions
diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py
index 8b53872e4..6691bb1fe 100644
--- a/module/plugins/hooks/ClickAndLoad.py
+++ b/module/plugins/hooks/ClickAndLoad.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import socket
+import time
from threading import Lock
@@ -18,44 +19,11 @@ def forward(source, destination):
destination.shutdown(socket.SHUT_WR)
-#: create_connection wrapper for python 2.5 socket module
-def create_connection(address, timeout=object(), source_address=None):
- if hasattr(socket, 'create_connection'):
- if type(timeout) == object:
- timeout = socket._GLOBAL_DEFAULT_TIMEOUT
-
- return socket.create_connection(address, timeout, source_address)
-
- else:
- host, port = address
- err = None
- for res in getaddrinfo(host, port, 0, SOCK_STREAM):
- af, socktype, proto, canonname, sa = res
- sock = None
- try:
- sock = socket(af, socktype, proto)
- if type(timeout) != object:
- sock.settimeout(timeout)
- if source_address:
- sock.bind(source_address)
- sock.connect(sa)
- return sock
-
- except socket.error, _:
- err = _
- if sock is not None:
- sock.close()
-
- if err is not None:
- raise err
- else:
- raise socket.error("getaddrinfo returns an empty list")
-
-
+#@TODO: IPv6 support
class ClickAndLoad(Hook):
__name__ = "ClickAndLoad"
__type__ = "hook"
- __version__ = "0.35"
+ __version__ = "0.37"
__config__ = [("activated", "bool", "Activated" , True),
("port" , "int" , "Port" , 9666),
@@ -76,7 +44,7 @@ class ClickAndLoad(Hook):
if not self.config['webinterface']['activated']:
return
- ip = socket.gethostbyname(socket.gethostname()) if self.getConfig("extern") else "127.0.0.1"
+ ip = "" if self.getConfig("extern") else "127.0.0.1"
webport = int(self.config['webinterface']['port'])
cnlport = self.getConfig('port')
@@ -85,6 +53,7 @@ class ClickAndLoad(Hook):
@threaded
def proxy(self, ip, webport, cnlport):
+ self.logInfo(_("Proxy listening on %s:%s") % (ip, cnlport))
self.manager.startThread(self._server, ip, webport, cnlport)
lock = Lock()
lock.acquire()
@@ -93,32 +62,31 @@ class ClickAndLoad(Hook):
def _server(self, ip, webport, cnlport, thread):
try:
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- server_socket.bind((ip, cnlport))
- server_socket.listen(5)
+ try:
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- while True:
- client_socket = server_socket.accept()[0]
- dock_socket = create_connection(("127.0.0.1", webport))
+ server_socket.bind((ip, cnlport))
+ server_socket.listen(5)
- self.manager.startThread(forward, dock_socket, client_socket)
- self.manager.startThread(forward, client_socket, dock_socket)
+ while True:
+ client_socket = server_socket.accept()[0]
+ dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- except socket.error, e:
- self.logDebug(e)
- self._server(ip, webport, cnlport, thread)
+ dock_socket.connect(("127.0.0.1", webport))
- except Exception, e:
- self.logError(e)
+ self.manager.startThread(forward, dock_socket, client_socket)
+ self.manager.startThread(forward, client_socket, dock_socket)
- try:
+ except socket.timeout:
+ self.logDebug("Connection timed out, retrying...")
+ return self._server(ip, webport, cnlport, thread)
+
+ finally:
+ server_socket.close()
client_socket.close()
dock_socket.close()
- except Exception:
- pass
- try:
- server_socket.close()
- except Exception:
- pass
+ except socket.error, e:
+ self.logError(e)
+ time.sleep(120)
+ self._server(ip, webport, cnlport, thread)
diff --git a/module/plugins/hooks/HotFolder.py b/module/plugins/hooks/HotFolder.py
index 1ff02c319..302bc909f 100644
--- a/module/plugins/hooks/HotFolder.py
+++ b/module/plugins/hooks/HotFolder.py
@@ -2,10 +2,9 @@
from __future__ import with_statement
+import os
import time
-from os import listdir, makedirs
-from os.path import exists, isfile, join
from shutil import move
from module.plugins.Hook import Hook
@@ -15,12 +14,12 @@ from module.utils import fs_encode, save_join
class HotFolder(Hook):
__name__ = "HotFolder"
__type__ = "hook"
- __version__ = "0.12"
+ __version__ = "0.13"
- __config__ = [("folder", "str", "Folder to observe", "container"),
- ("watch_file", "bool", "Observe link file", False),
- ("keep", "bool", "Keep added containers", True),
- ("file", "str", "Link file", "links.txt")]
+ __config__ = [("folder" , "str" , "Folder to observe" , "container"),
+ ("watch_file", "bool", "Observe link file" , False ),
+ ("keep" , "bool", "Keep added containers", True ),
+ ("file" , "str" , "Link file" , "links.txt")]
__description__ = """Observe folder and file for changes and add container and links"""
__license__ = "GPLv3"
@@ -28,36 +27,40 @@ class HotFolder(Hook):
def setup(self):
- self.interval = 10
+ self.interval = 30
def periodical(self):
folder = fs_encode(self.getConfig("folder"))
+ file = fs_encode(self.getConfig("file"))
try:
- if not exists(join(folder, "finished")):
- makedirs(join(folder, "finished"))
+ if not os.path.isdir(os.path.join(folder, "finished")):
+ os.makedirs(os.path.join(folder, "finished"))
if self.getConfig("watch_file"):
- file = fs_encode(self.getConfig("file"))
with open(file, "a+") as f:
+ f.seek(0)
content = f.read().strip()
if content:
- name = "%s_%s.txt" % (self.getConfig("file"), time.strftime("%H-%M-%S_%d%b%Y"))
+ f = open(file, "wb")
+ f.close()
+
+ name = "%s_%s.txt" % (file, time.strftime("%H-%M-%S_%d%b%Y"))
with open(save_join(folder, "finished", name), "wb") as f:
f.write(content)
self.core.api.addPackage(f.name, [f.name], 1)
- for f in listdir(folder):
- path = join(folder, f)
+ for f in os.listdir(folder):
+ path = os.path.join(folder, f)
- if not isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."):
+ if not os.path.isfile(path) or f.endswith("~") or f.startswith("#") or f.startswith("."):
continue
- newpath = join(folder, "finished", f if self.getConfig("keep") else "tmp_" + f)
+ newpath = os.path.join(folder, "finished", f if self.getConfig("keep") else "tmp_" + f)
move(path, newpath)
self.logInfo(_("Added %s from HotFolder") % f)
diff --git a/module/plugins/hooks/XFileSharingPro.py b/module/plugins/hooks/XFileSharingPro.py
index a1ee7f5ef..495140652 100644
--- a/module/plugins/hooks/XFileSharingPro.py
+++ b/module/plugins/hooks/XFileSharingPro.py
@@ -8,7 +8,7 @@ from module.plugins.Hook import Hook
class XFileSharingPro(Hook):
__name__ = "XFileSharingPro"
__type__ = "hook"
- __version__ = "0.31"
+ __version__ = "0.32"
__config__ = [("activated" , "bool", "Activated" , True ),
("use_hoster_list" , "bool", "Load listed hosters only" , False),
@@ -29,7 +29,7 @@ class XFileSharingPro(Hook):
r'https?://(?:[^/]+\.)?(?P<DOMAIN>%s)/(?:user|folder)s?/\w+')}
HOSTER_BUILTIN = [#WORKING HOSTERS:
- "180upload.com", "backin.net", "eyesfile.ca", "file4safe.com", "fileband.com", "filedwon.com",
+ "backin.net", "eyesfile.ca", "file4safe.com", "fileband.com", "filedwon.com",
"fileparadox.in", "filevice.com", "hostingbulk.com", "junkyvideo.com", "linestorage.com", "ravishare.com",
"ryushare.com", "salefiles.com", "sendmyway.com", "sharesix.com", "thefile.me", "verzend.be", "xvidstage.com",
#NOT TESTED: