diff options
author | Walter Purcaro <vuolter@gmail.com> | 2015-02-22 17:06:38 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2015-02-22 17:06:38 +0100 |
commit | 38995b29744a0a4101a3b26c53f5f0a60b30bda4 (patch) | |
tree | 0a6d7d06bb4cddead1ac7416c19331db917b38e4 /pyload/plugin/addon | |
parent | Tiny code cosmetics (diff) | |
parent | [HotFolder] Fixup (thx zapp-brannigan) (diff) | |
download | pyload-38995b29744a0a4101a3b26c53f5f0a60b30bda4.tar.xz |
Merge branch 'stable' into 0.4.10
Conflicts:
module/plugins/container/LinkList.py
module/plugins/container/TXT.py
module/plugins/hoster/HundredEightyUploadCom.py
pyload/plugin/Extractor.py
pyload/plugin/addon/ClickAndLoad.py
pyload/plugin/addon/ExtractArchive.py
pyload/plugin/addon/HotFolder.py
pyload/plugin/container/TXT.py
pyload/plugin/extractor/SevenZip.py
pyload/plugin/extractor/UnRar.py
pyload/plugin/extractor/UnZip.py
pyload/plugin/hook/XFileSharingPro.py
pyload/plugin/hoster/ZippyshareCom.py
Diffstat (limited to 'pyload/plugin/addon')
-rw-r--r-- | pyload/plugin/addon/ClickAndLoad.py | 86 | ||||
-rw-r--r-- | pyload/plugin/addon/ExtractArchive.py | 136 | ||||
-rw-r--r-- | pyload/plugin/addon/HotFolder.py | 27 |
3 files changed, 126 insertions, 123 deletions
diff --git a/pyload/plugin/addon/ClickAndLoad.py b/pyload/plugin/addon/ClickAndLoad.py index 98e650d15..c5042ede6 100644 --- a/pyload/plugin/addon/ClickAndLoad.py +++ b/pyload/plugin/addon/ClickAndLoad.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import socket +import time from threading import Lock @@ -18,48 +19,15 @@ 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(Addon): __name = "ClickAndLoad" __type = "addon" - __version = "0.35" + __version = "0.37" __config = [("activated", "bool", "Activated" , True), - ("port" , "int" , "Port" , 9666), - ("extern" , "bool", "Listen on the public network interface", True)] + ("port" , "int" , "Port" , 9666), + ("extern" , "bool", "Listen on the public network interface", True)] __description = """Click'N'Load addon plugin""" __license = "GPLv3" @@ -71,7 +39,7 @@ class ClickAndLoad(Addon): 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') @@ -80,6 +48,7 @@ class ClickAndLoad(Addon): @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() @@ -88,32 +57,31 @@ class ClickAndLoad(Addon): 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/pyload/plugin/addon/ExtractArchive.py b/pyload/plugin/addon/ExtractArchive.py index 9cd8fad62..29b2165ca 100644 --- a/pyload/plugin/addon/ExtractArchive.py +++ b/pyload/plugin/addon/ExtractArchive.py @@ -104,13 +104,14 @@ class ArchiveQueue(object): class ExtractArchive(Addon): __name = "ExtractArchive" __type = "addon" - __version = "1.29" + __version = "1.30" __config = [("activated" , "bool" , "Activated" , True ), ("fullpath" , "bool" , "Extract with full paths" , True ), ("overwrite" , "bool" , "Overwrite files" , False ), ("keepbroken" , "bool" , "Try to extract broken archives" , False ), - ("repair" , "bool" , "Repair broken archives" , True ), + ("repair" , "bool" , "Repair broken archives (rar required)" , False ), + ("test" , "bool" , "Test archive before extracting" , False ), ("usepasswordfile" , "bool" , "Use password file" , True ), ("passwordfile" , "file" , "Password file" , "archive_password.txt" ), ("delete" , "bool" , "Delete archive when successfully extracted", False ), @@ -128,7 +129,7 @@ class ExtractArchive(Addon): ("Immenz" , "immenz@gmx.net" )] - event_list = ["allDownloadsProcessed"] + event_list = ["allDownloadsProcessed","packageDeleted"] NAME_REPLACEMENTS = [(r'\.part\d+\.rar$', ".part.rar")] @@ -137,21 +138,23 @@ class ExtractArchive(Addon): self.queue = ArchiveQueue(self, "Queue") self.failed = ArchiveQueue(self, "Failed") - self.interval = 60 - self.extracting = False - self.extractors = [] - self.passwords = [] + self.interval = 60 + self.extracting = False + self.lastPackage = False + self.extractors = [] + self.passwords = [] + self.repair = False def activate(self): - # self.extracting = False - for p in ("UnRar", "SevenZip", "UnZip"): try: module = self.core.pluginManager.loadModule("extractor", p) klass = getattr(module, p) if klass.isUsable(): self.extractors.append(klass) + if klass.REPAIR: + self.repair = self.getConfig("repair") except OSError, e: if e.errno == 2: @@ -168,37 +171,49 @@ class ExtractArchive(Addon): if self.extractors: self.logInfo(_("Activated") + " " + "|".join("%s %s" % (Extractor.__name,Extractor.VERSION) for Extractor in self.extractors)) - - if self.getConfig("waitall"): - self.extractPackage(*self.queue.get()) #: Resume unfinished extractions - else: - super(ExtractArchive, self).initPeriodical() - + self.extractQueued() #: Resume unfinished extractions else: self.logInfo(_("No Extract plugins activated")) + @threaded + def extractQueued(self,thread): + packages = self.queue.get() + while packages: + if self.lastPackage: # called from allDownloadsProcessed + self.lastPackage = False + if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now + self.manager.dispatchEvent("all_archives_extracted") + self.manager.dispatchEvent("all_archives_processed") + else: + if self.extract(packages, thread): #@NOTE: check only if all gone fine, no failed reporting for now + pass - def periodical(self): - if not self.extracting: - self.extractPackage(*self.queue.get()) + packages = self.queue.get() # check for packages added during extraction @Expose def extractPackage(self, *ids): """ Extract packages with given id""" - self.manager.startThread(self.extract, ids) + for id in ids: + self.queue.add(id) + if not self.getConfig("waitall") and not self.extracting: + self.extractQueued() + + + def packageDeleted(self, pid): + self.queue.remove(pid) def packageFinished(self, pypack): self.queue.add(pypack.id) + if not self.getConfig("waitall") and not self.extracting: + self.extractQueued() - @threaded - def allDownloadsProcessed(self, thread): - if self.extract(self.queue.get(), thread): #@NOTE: check only if all gone fine, no failed reporting for now - self.manager.dispatchEvent("all_archives_extracted") - - self.manager.dispatchEvent("all_archives_processed") + def allDownloadsProcessed(self): + self.lastPackage = True + if not self.extracting: + self.extractQueued() def extract(self, ids, thread=None): @@ -311,12 +326,16 @@ class ExtractArchive(Addon): if recursive and os.path.isfile(file): new_files_ids.append((filename, fid, os.path.dirname(filename))) # append as new target + pyfile = self.core.files.getFile(fid) + self.manager.dispatchEvent("archive_extracted", pyfile, archive.out, archive.filename, new_files) + files_ids = new_files_ids # also check extracted files if matched: if success: extracted.append(pid) self.manager.dispatchEvent("package_extracted", pypack) + else: failed.append(pid) self.manager.dispatchEvent("package_extract_failed", pypack) @@ -347,50 +366,65 @@ class ExtractArchive(Addon): encrypted = False try: - try: - archive.check() + self.logDebug("Password: %s" % (password or "None provided")) + passwords = uniqify([password] + self.getPasswords(False)) if self.getConfig("usepasswordfile") else [password] + for pw in passwords: + try: + if self.getConfig("test") or self.repair: + pyfile.setCustomStatus(_("testing")) + if pw: + self.logDebug("Testing with password: %s" % pw) + pyfile.setProgress(0) + archive.test(pw) + pyfile.setProgress(100) + else: + archive.check(pw) - except CRCError, e: - self.logDebug(name, e) - self.logInfo(name, _("Header protected")) + self.addPassword(pw) + break - if self.getConfig("repair"): - self.logWarning(name, _("Repairing...")) + except PasswordError: + if not encrypted: + self.logInfo(name, _("Password protected")) + encrypted = True - pyfile.setCustomStatus(_("repairing")) - pyfile.setProgress(0) + except CRCError, e: + self.logDebug(name, e) + self.logInfo(name, _("CRC Error")) - repaired = archive.repair() + if self.repair: + self.logWarning(name, _("Repairing...")) - pyfile.setProgress(100) + pyfile.setCustomStatus(_("repairing")) + pyfile.setProgress(0) + repaired = archive.repair() + pyfile.setProgress(100) - if not repaired and not self.getConfig("keepbroken"): - raise CRCError("Archive damaged") + if not repaired and not self.getConfig("keepbroken"): + raise CRCError("Archive damaged") - except PasswordError: - self.logInfo(name, _("Password protected")) - encrypted = True + self.addPassword(pw) + break - except ArchiveError, e: - raise ArchiveError(e) + raise CRCError("Archive damaged") - self.logDebug("Password: %s" % (password or "No provided")) + except ArchiveError, e: + raise ArchiveError(e) pyfile.setCustomStatus(_("extracting")) pyfile.setProgress(0) if not encrypted or not self.getConfig("usepasswordfile"): + self.logDebug("Extracting using password: %s" % (password or "None")) archive.extract(password) else: for pw in filter(None, uniqify([password] + self.getPasswords(False))): try: - self.logDebug("Try password: %s" % pw) + self.logDebug("Extracting using password: %s" % pw) - ispw = archive.isPassword(pw) - if ispw or ispw is None: - archive.extract(pw) - self.addPassword(pw) - break + archive.extract(pw) + self.addPassword(pw) + break except PasswordError: self.logDebug("Password was wrong") @@ -414,9 +448,7 @@ class ExtractArchive(Addon): self.logDebug("%s does not exists" % f) self.logInfo(name, _("Extracting finished")) - extracted_files = archive.files or archive.list() - self.manager.dispatchEvent("archive_extracted", pyfile, archive.out, archive.filename, extracted_files) return extracted_files diff --git a/pyload/plugin/addon/HotFolder.py b/pyload/plugin/addon/HotFolder.py index 6b1f6c02e..f2c8a96a4 100644 --- a/pyload/plugin/addon/HotFolder.py +++ b/pyload/plugin/addon/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 pyload.plugin.Addon import Addon @@ -15,7 +14,7 @@ from pyload.utils import fs_encode, safe_join class HotFolder(Addon): __name = "HotFolder" __type = "addon" - __version = "0.12" + __version = "0.13" __config = [("folder" , "str" , "Folder to observe" , "container"), ("watch_file", "bool", "Observe link file" , False ), @@ -28,7 +27,7 @@ class HotFolder(Addon): def setup(self): - self.interval = 10 + self.interval = 30 def activate(self): @@ -37,31 +36,35 @@ class HotFolder(Addon): 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(safe_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) |