summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar sraedler <simon.raedler@yahoo.de> 2015-04-08 01:58:10 +0200
committerGravatar sraedler <simon.raedler@yahoo.de> 2015-04-08 01:58:10 +0200
commita59784a64f8afdca1642a0e53a396548a8608d61 (patch)
treea7eb9914bbc55bbc46f5a5f6929c6c6c95c81244 /module
parentFixed RemixshareCom (diff)
parent[ExtractArchive] Fix https://github.com/pyload/pyload/issues/1322 (diff)
downloadpyload-a59784a64f8afdca1642a0e53a396548a8608d61.tar.xz
Merge pull request #1 from pyload/stable
merge with base
Diffstat (limited to 'module')
-rw-r--r--module/plugins/hooks/AntiVirus.py38
-rw-r--r--module/plugins/hooks/ExtractArchive.py89
-rw-r--r--module/plugins/hooks/IRCInterface.py4
-rw-r--r--module/plugins/hooks/MergeFiles.py5
-rw-r--r--module/plugins/hooks/UserAgentSwitcher.py32
-rw-r--r--module/plugins/hoster/YadiSk.py45
-rw-r--r--module/plugins/internal/MultiHook.py5
-rw-r--r--module/plugins/internal/SimpleDereferer.py4
-rw-r--r--module/plugins/internal/SimpleHoster.py4
9 files changed, 139 insertions, 87 deletions
diff --git a/module/plugins/hooks/AntiVirus.py b/module/plugins/hooks/AntiVirus.py
index cc3c5c754..78f5aaa23 100644
--- a/module/plugins/hooks/AntiVirus.py
+++ b/module/plugins/hooks/AntiVirus.py
@@ -11,15 +11,16 @@ from module.utils import fs_encode, save_join
class AntiVirus(Hook):
__name__ = "AntiVirus"
__type__ = "hook"
- __version__ = "0.05"
+ __version__ = "0.06"
#@TODO: add trash option (use Send2Trash lib)
- __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"),
- ("quardir" , "folder" , "Quarantine folder" , "" ),
- ("scanfailed", "bool" , "Scan incompleted files (failed downloads)", False ),
- ("cmdfile" , "file" , "Antivirus executable" , "" ),
- ("cmdargs" , "str" , "Scan options" , "" ),
- ("ignore-err", "bool" , "Ignore scan errors" , False )]
+ __config__ = [("action" , "Antivirus default;Delete;Quarantine", "Manage infected files" , "Antivirus default"),
+ ("quardir" , "folder" , "Quarantine folder" , "" ),
+ ("deltotrash", "bool" , "Move to trash (recycle bin) instead delete", True ),
+ ("scanfailed", "bool" , "Scan incompleted files (failed downloads)" , False ),
+ ("cmdfile" , "file" , "Antivirus executable" , "" ),
+ ("cmdargs" , "str" , "Scan options" , "" ),
+ ("ignore-err", "bool" , "Ignore scan errors" , False )]
__description__ = """Scan downloaded files with antivirus program"""
__license__ = "GPLv3"
@@ -32,6 +33,16 @@ class AntiVirus(Hook):
def setup(self):
self.info = {} #@TODO: Remove in 0.4.10
+ try:
+ import send2trash
+
+ except ImportError:
+ self.logDebug(name, _("Send2Trash lib not found"))
+ self.trashable = False
+
+ else:
+ self.trashable = True
+
@Expose
@threaded
@@ -46,6 +57,7 @@ class AntiVirus(Hook):
thread.addActive(pyfile)
pyfile.setCustomStatus(_("virus scanning"))
+ pyfile.setProgress(0)
try:
p = subprocess.Popen([cmdfile, cmdargs, file], bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -66,11 +78,19 @@ class AntiVirus(Hook):
action = self.getConfig('action')
try:
if action == "Delete":
- os.remove(file)
+ if not self.getConfig('deltotrash'):
+ os.remove(file)
+
+ elif self.trashable:
+ send2trash.send2trash(file)
+
+ else:
+ self.logWarning(_("Unable to move file to trash, move to quarantine instead"))
+ pyfile.setCustomStatus(_("file moving"))
+ shutil.move(file, self.getConfig('quardir'))
elif action == "Quarantine":
pyfile.setCustomStatus(_("file moving"))
- pyfile.setProgress(0)
shutil.move(file, self.getConfig('quardir'))
except (IOError, shutil.Error), e:
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index 8c40667c2..b418f802f 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -4,9 +4,9 @@ from __future__ import with_statement
import os
import sys
+import traceback
from copy import copy
-from traceback import print_exc
# monkey patch bug in python 2.6 and lower
# http://bugs.python.org/issue6122 , http://bugs.python.org/issue1236 , http://bugs.python.org/issue1731717
@@ -106,24 +106,25 @@ class ArchiveQueue(object):
class ExtractArchive(Hook):
__name__ = "ExtractArchive"
__type__ = "hook"
- __version__ = "1.38"
-
- __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 (RAR required)" , False ),
- ("test" , "bool" , "Test archive before extracting" , False ),
- ("usepasswordfile", "bool" , "Use password file" , True ),
- ("passwordfile" , "file" , "Password file" , "archive_password.txt" ),
- ("delete" , "No;Permanent;Trash", "Delete archive after extraction" , "No" ),
- ("subfolder" , "bool" , "Create subfolder for each package" , False ),
- ("destination" , "folder" , "Extract files to folder" , "" ),
- ("extensions" , "str" , "Extract archives ending with extension", "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"),
- ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ),
- ("recursive" , "bool" , "Extract archives in archives" , True ),
- ("waitall" , "bool" , "Run after all downloads was processed" , False ),
- ("renice" , "int" , "CPU priority" , 0 )]
+ __version__ = "1.40"
+
+ __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 (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 after extraction" , True ),
+ ("deltotrash" , "bool" , "Move to trash (recycle bin) instead delete", True ),
+ ("subfolder" , "bool" , "Create subfolder for each package" , False ),
+ ("destination" , "folder" , "Extract files to folder" , "" ),
+ ("extensions" , "str" , "Extract archives ending with extension" , "7z,bz2,bzip2,gz,gzip,lha,lzh,lzma,rar,tar,taz,tbz,tbz2,tgz,xar,xz,z,zip"),
+ ("excludefiles" , "str" , "Don't extract the following files" , "*.nfo,*.DS_Store,index.dat,thumb.db" ),
+ ("recursive" , "bool" , "Extract archives in archives" , True ),
+ ("waitall" , "bool" , "Run after all downloads was processed" , False ),
+ ("renice" , "int" , "CPU priority" , 0 )]
__description__ = """Extract different kind of archives"""
__license__ = "GPLv3"
@@ -148,7 +149,16 @@ class ExtractArchive(Hook):
self.extractors = []
self.passwords = []
self.repair = False
- self.trash = False
+
+ try:
+ import send2trash
+
+ except ImportError:
+ self.logDebug(name, _("Send2Trash lib not found"))
+ self.trashable = False
+
+ else:
+ self.trashable = True
def coreReady(self):
@@ -167,12 +177,12 @@ class ExtractArchive(Hook):
else:
self.logWarning(_("Could not activate: %s") % p, e)
if self.core.debug:
- print_exc()
+ traceback.print_exc()
except Exception, e:
self.logWarning(_("Could not activate: %s") % p, e)
if self.core.debug:
- print_exc()
+ traceback.print_exc()
if self.extractors:
self.logInfo(_("Activated") + " " + "|".join("%s %s" % (Extractor.__name__, Extractor.VERSION) for Extractor in self.extractors))
@@ -321,6 +331,7 @@ class ExtractArchive(Hook):
new_files = self._extract(pyfile, archive, pypack.password)
finally:
+ pyfile.setProgress(100)
thread.finishFile(pyfile)
except Exception, e:
@@ -449,31 +460,25 @@ class ExtractArchive(Hook):
pyfile.setStatus("processing")
delfiles = archive.getDeleteFiles()
- if self.core.debug:
- self.logDebug("Would delete: %s" % ", ".join(delfiles))
+ self.logDebug("Would delete: " + ", ".join(delfiles))
- if self.getConfig('delete') != 'No':
- try:
- from send2trash import send2trash
- if self.getConfig('delete') == "Trash":
- self.trash = True
- self.logInfo(_("Sending %s files to trash") % len(delfiles))
- except ImportError:
- self.logError(name, _("Send2Trash not installed, no files deleted"))
- self.trash = False
-
- if self.getConfig('delete') == "Permanent":
- self.trash = False
- self.logInfo(_("Deleting %s files") % len(delfiles))
+ if self.getConfig('delete'):
+ self.logInfo(_("Deleting %s files") % len(delfiles))
+ deltotrash = self.getConfig('deltotrash')
for f in delfiles:
file = fs_encode(f)
- if os.path.exists(file) and self.trash:
- send2trash(file)
- elif os.path.exists(file):
+ if not os.path.exists(file):
+ continue
+
+ if not deltotrash:
os.remove(file)
+
+ elif self.trashable:
+ send2trash.send2trash(file)
+
else:
- self.logDebug("%s does not exists" % f)
+ self.logWarning(_("Unable to move %s to trash") % os.path.basename(f))
self.logInfo(name, _("Extracting finished"))
extracted_files = archive.files or archive.list()
@@ -492,7 +497,7 @@ class ExtractArchive(Hook):
except Exception, e:
self.logError(name, _("Unknown error"), e)
if self.core.debug:
- print_exc()
+ traceback.print_exc()
self.manager.dispatchEvent("archive_extract_failed", pyfile, archive)
diff --git a/module/plugins/hooks/IRCInterface.py b/module/plugins/hooks/IRCInterface.py
index d76b9cb85..9e2f670e6 100644
--- a/module/plugins/hooks/IRCInterface.py
+++ b/module/plugins/hooks/IRCInterface.py
@@ -4,11 +4,11 @@ import re
import socket
import ssl
import time
+import traceback
from pycurl import FORM_FILE
from select import select
from threading import Thread
-from traceback import print_exc
from module.Api import PackageDoesNotExists, FileDoesNotExists
from module.network.RequestFactory import getURL
@@ -106,7 +106,7 @@ class IRCInterface(Thread, Hook):
except IRCError, ex:
self.sock.send("QUIT :byebye\r\n")
- print_exc()
+ traceback.print_exc()
self.sock.close()
diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py
index 2900b0d29..941938920 100644
--- a/module/plugins/hooks/MergeFiles.py
+++ b/module/plugins/hooks/MergeFiles.py
@@ -4,8 +4,7 @@ from __future__ import with_statement
import os
import re
-
-from traceback import print_exc
+import traceback
from module.plugins.Hook import Hook, threaded
from module.utils import save_join
@@ -75,7 +74,7 @@ class MergeFiles(Hook):
self.logDebug("Finished merging part", splitted_file)
except Exception, e:
- print_exc()
+ traceback.print_exc()
finally:
pyfile.setProgress(100)
diff --git a/module/plugins/hooks/UserAgentSwitcher.py b/module/plugins/hooks/UserAgentSwitcher.py
new file mode 100644
index 000000000..31eac9820
--- /dev/null
+++ b/module/plugins/hooks/UserAgentSwitcher.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+
+import pycurl
+
+from module.plugins.Hook import Hook
+
+
+class UserAgentSwitcher(Hook):
+ __name__ = "UserAgentSwitcher"
+ __type__ = "hook"
+ __version__ = "0.02"
+
+ __config__ = [("activated", "bool", "Activated" , True ),
+ ("ua" , "str" , "Custom user-agent string", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0")]
+
+ __description__ = """Custom user-agent"""
+ __license__ = "GPLv3"
+ __authors__ = [("Walter Purcaro", "vuolter@gmail.com")]
+
+
+ interval = 0 #@TODO: Remove in 0.4.10
+
+
+ def setup(self):
+ self.info = {} #@TODO: Remove in 0.4.10
+
+
+ def downloadPreparing(self, pyfile):
+ ua = self.getConfig('ua')
+ if ua:
+ self.logDebug("Use custom user-agent string: " + ua)
+ pyfile.plugin.req.http.c.setopt(pycurl.USERAGENT, ua)
diff --git a/module/plugins/hoster/YadiSk.py b/module/plugins/hoster/YadiSk.py
index 57d8ae786..c3749d30d 100644
--- a/module/plugins/hoster/YadiSk.py
+++ b/module/plugins/hoster/YadiSk.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import re
-import pycurl
import random
from module.common.json_layer import json_loads
@@ -11,13 +10,13 @@ from module.plugins.internal.SimpleHoster import SimpleHoster, create_getInfo
class YadiSk(SimpleHoster):
__name__ = "YadiSk"
__type__ = "hoster"
- __version__ = "0.02"
+ __version__ = "0.03"
__pattern__ = r'https?://yadi\.sk/d/\w+'
__description__ = """Yadi.sk hoster plugin"""
__license__ = "GPLv3"
- __authors__ = [("GammaC0de", "nomail@fakemailbox.com")]
+ __authors__ = [("GammaC0de", None)]
OFFLINE_PATTERN = r'Nothing found'
@@ -32,7 +31,7 @@ class YadiSk(SimpleHoster):
def handleFree(self, pyfile):
m = re.search(r'<script id="models-client" type="application/json">(.+?)</script>', self.html)
if m is None:
- self.fail(_("could not find required json data"))
+ self.error(_("could not find required json data"))
res = json_loads(m.group(1))
@@ -41,45 +40,45 @@ class YadiSk(SimpleHoster):
yadisk_id = None
yadisk_size = None
yadisk_name = None
- yadisk_hash = None
- try: #@TODO: Copy to apiInfo method
+
+ try: #@TODO: Copy to apiInfo
for sect in res:
if 'model' in sect:
- if sect['model'] == 'config':
+ if sect['model'] == "config":
yadisk_ver = sect['data']['version']
yadisk_sk = sect['data']['sk']
- elif sect['model'] == 'resource':
+ elif sect['model'] == "resource":
yadisk_id = sect['data']['id']
yadisk_size = sect['data']['meta']['size']
yadisk_name = sect['data']['name']
- except Exception:
- self.fail(_("Unexpected server response"))
+ except Exception, e:
+ self.fail(_("Unexpected server response"), e)
- if None is in (yadisk_id, yadisk_sk, yadisk_id, yadisk_size, yadisk_name):
- self.fail(_("json data is missing important information, cannot continue"))
+ if None in (yadisk_id, yadisk_sk, yadisk_id, yadisk_size, yadisk_name):
+ self.error(_("Missing JSON data"))
self.pyfile.size = yadisk_size
self.pyfile.name = yadisk_name
yadisk_idclient = ""
- for _i in range(1, 32):
+ for _i in range(32):
yadisk_idclient += random.choice('0123456abcdef')
- result_json = self.load("https://yadi.sk/models/?_m=do-get-resource-url",
- post={'idClient': yadisk_idclient,
- 'version' : yadisk_ver,
- '_model.0': "do-get-resource-url",
- 'sk' : yadisk_sk,
- 'id.0' : yadisk_id})
-
- res = json_loads(result_json)
try:
- self.link = res['models'][0]['data']['file']
+ self.html = self.load("https://yadi.sk/models/",
+ get={'_m': "do-get-resource-url"},
+ post={'idClient': yadisk_idclient,
+ 'version' : yadisk_ver,
+ '_model.0': "do-get-resource-url",
+ 'sk' : yadisk_sk,
+ 'id.0' : yadisk_id})
+
+ self.link = json_loads(self.html)['models'][0]['data']['file']
except Exception:
- self.fail(_("faild to retrieve the download url"))
+ pass
getInfo = create_getInfo(YadiSk)
diff --git a/module/plugins/internal/MultiHook.py b/module/plugins/internal/MultiHook.py
index 291063268..942c044c2 100644
--- a/module/plugins/internal/MultiHook.py
+++ b/module/plugins/internal/MultiHook.py
@@ -2,6 +2,7 @@
import re
import time
+import traceback
from module.plugins.Hook import Hook
from module.utils import decode, remove_chars
@@ -10,7 +11,7 @@ from module.utils import decode, remove_chars
class MultiHook(Hook):
__name__ = "MultiHook"
__type__ = "hook"
- __version__ = "0.41"
+ __version__ = "0.42"
__config__ = [("pluginmode" , "all;listed;unlisted", "Use for plugins" , "all"),
("pluginlist" , "str" , "Plugin list (comma separated)", "" ),
@@ -188,7 +189,7 @@ class MultiHook(Hook):
except Exception, e:
self.core.log.error(_("Error executing hooks: %s") % str(e))
if self.core.debug:
- print_exc()
+ traceback.print_exc()
self.cb = self.core.scheduler.addJob(self.interval, self._periodical)
diff --git a/module/plugins/internal/SimpleDereferer.py b/module/plugins/internal/SimpleDereferer.py
index bdb2d773c..743a98721 100644
--- a/module/plugins/internal/SimpleDereferer.py
+++ b/module/plugins/internal/SimpleDereferer.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
-import pycurl
import re
from urllib import unquote
@@ -12,7 +11,7 @@ from module.plugins.internal.SimpleHoster import getFileURL, set_cookies
class SimpleDereferer(Crypter):
__name__ = "SimpleDereferer"
__type__ = "crypter"
- __version__ = "0.10"
+ __version__ = "0.11"
__pattern__ = r'^unmatchable$'
__config__ = [("use_subfolder" , "bool", "Save package to subfolder" , True),
@@ -71,7 +70,6 @@ class SimpleDereferer(Crypter):
self.html = ""
self.req.setOption("timeout", 120)
- self.req.http.c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0") #@NOTE: Work-around to old user-agent bug; remove in 0.4.10
if isinstance(self.COOKIES, list):
set_cookies(self.req.cj, self.COOKIES)
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 0474a5af5..79b7c0534 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -3,7 +3,6 @@
import datetime
import mimetypes
import os
-import pycurl
import re
import time
import urllib2
@@ -248,7 +247,7 @@ def secondsToMidnight(gmt=0):
class SimpleHoster(Hoster):
__name__ = "SimpleHoster"
__type__ = "hoster"
- __version__ = "1.34"
+ __version__ = "1.35"
__pattern__ = r'^unmatchable$'
__config__ = [("use_premium", "bool", "Use premium account if available", True)]
@@ -434,7 +433,6 @@ class SimpleHoster(Hoster):
self.fail(_("Required account not found"))
self.req.setOption("timeout", 120)
- self.req.http.c.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0") #@NOTE: Work-around to old user-agent bug; remove in 0.4.10
if isinstance(self.COOKIES, list):
set_cookies(self.req.cj, self.COOKIES)