summaryrefslogtreecommitdiffstats
path: root/module/plugins/internal/UnRar.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins/internal/UnRar.py')
-rw-r--r--module/plugins/internal/UnRar.py53
1 files changed, 31 insertions, 22 deletions
diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py
index 19c278735..c15a4c96e 100644
--- a/module/plugins/internal/UnRar.py
+++ b/module/plugins/internal/UnRar.py
@@ -4,7 +4,7 @@ import os
import re
from glob import glob
-from os.path import join
+from os.path import basename, join
from string import digits
from subprocess import Popen, PIPE
@@ -12,23 +12,32 @@ from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPas
from module.utils import save_join, decode
+def renice(pid, value):
+ if os.name != "nt" and value:
+ try:
+ Popen(["renice", str(value), str(pid)], stdout=PIPE, stderr=PIPE, bufsize=-1)
+ except:
+ print "Renice failed"
+
+
class UnRar(AbtractExtractor):
- __name__ = "UnRar"
- __version__ = "0.16"
+ __name__ = "UnRar"
+ __version__ = "0.19"
__description__ = """Rar extractor plugin"""
- __author_name__ = "RaNaN"
- __author_mail__ = "RaNaN@pyload.org"
+ __license__ = "GPLv3"
+ __authors__ = [("RaNaN", "RaNaN@pyload.org")]
+
CMD = "unrar"
# there are some more uncovered rar formats
- re_version = re.compile(r"(UNRAR 5[\.\d]+(.*?)freeware)")
- re_splitfile = re.compile(r"(.*)\.part(\d+)\.rar$", re.I)
- re_partfiles = re.compile(r".*\.(rar|r[0-9]+)", re.I)
- re_filelist = re.compile(r"(.+)\s+(\d+)\s+(\d+)\s+")
- re_filelist5 = re.compile(r"(.+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)")
- re_wrongpwd = re.compile("(Corrupt file or wrong password|password incorrect)", re.I)
+ re_version = re.compile(r'UNRAR ([\w .]+?) freeware')
+ re_splitfile = re.compile(r'(.*)\.part(\d+)\.rar$', re.I)
+ re_partfiles = re.compile(r'.*\.(rar|r\d+)', re.I)
+ re_filelist = re.compile(r'(.+)\s+(\d+)\s+(\d+)\s+')
+ re_filelist5 = re.compile(r'(.+)\s+(\d+)\s+\d\d-\d\d-\d\d\s+\d\d:\d\d\s+(.+)')
+ re_wrongpwd = re.compile(r'(Corrupt file or wrong password|password incorrect)', re.I)
@staticmethod
@@ -50,6 +59,7 @@ class UnRar(AbtractExtractor):
return True
+
@staticmethod
def getTargets(files_ids):
result = []
@@ -68,12 +78,14 @@ class UnRar(AbtractExtractor):
return result
+
def init(self):
self.passwordProtected = False
self.headerProtected = False #: list files will not work without password
self.smallestFile = None #: small file to test passwords
self.password = "" #: save the correct password
+
def checkArchive(self):
p = self.call_unrar("l", "-v", self.file)
out, err = p.communicate()
@@ -100,6 +112,7 @@ class UnRar(AbtractExtractor):
return False
+
def checkPassword(self, password):
# at this point we can only verify header protected files
if self.headerProtected:
@@ -110,6 +123,7 @@ class UnRar(AbtractExtractor):
return True
+
def extract(self, progress, password=None):
command = "x" if self.fullpath else "e"
@@ -151,13 +165,15 @@ class UnRar(AbtractExtractor):
self.password = password
self.listContent()
+
def getDeleteFiles(self):
- if ".part" in self.file:
- return glob(re.sub("(?<=\.part)([01]+)", "*", self.file, re.IGNORECASE))
+ if ".part" in basename(self.file):
+ return glob(re.sub("(?<=\.part)([01]+)", "*", self.file, re.I))
# get files which matches .r* and filter unsuited files out
- parts = glob(re.sub(r"(?<=\.r)ar$", "*", self.file, re.IGNORECASE))
+ parts = glob(re.sub(r"(?<=\.r)ar$", "*", self.file, re.I))
return filter(lambda x: self.re_partfiles.match(x), parts)
+
def listContent(self):
command = "vb" if self.fullpath else "lb"
p = self.call_unrar(command, "-v", self.file, password=self.password)
@@ -177,6 +193,7 @@ class UnRar(AbtractExtractor):
self.files = result
+
def call_unrar(self, command, *xargs, **kwargs):
args = []
# overwrite flag
@@ -202,11 +219,3 @@ class UnRar(AbtractExtractor):
p = Popen(call, stdout=PIPE, stderr=PIPE)
return p
-
-
-def renice(pid, value):
- if os.name != "nt" and value:
- try:
- Popen(["renice", str(value), str(pid)], stdout=PIPE, stderr=PIPE, bufsize=-1)
- except:
- print "Renice failed"