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.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/module/plugins/internal/UnRar.py b/module/plugins/internal/UnRar.py
index 240dc0233..da8e7cf3d 100644
--- a/module/plugins/internal/UnRar.py
+++ b/module/plugins/internal/UnRar.py
@@ -22,18 +22,20 @@ import re
from os.path import join
from glob import glob
from subprocess import Popen, PIPE
+from string import digits
from module.utils import save_join, decode
from module.plugins.internal.AbstractExtractor import AbtractExtractor, WrongPassword, ArchiveError, CRCError
class UnRar(AbtractExtractor):
__name__ = "UnRar"
- __version__ = "0.11"
+ __version__ = "0.13"
# there are some more uncovered rar formats
- re_splitfile = re.compile(r"(.*)\.part(\d+)\.rar$")
+ 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_wrongpwd = re.compile("(Corrupt file or wrong password|password incorrect)")
+ re_wrongpwd = re.compile("(Corrupt file or wrong password|password incorrect)", re.I)
CMD = "unrar"
@staticmethod
@@ -113,15 +115,31 @@ class UnRar(AbtractExtractor):
def extract(self, progress, password=None):
command = "x" if self.fullpath else "e"
- # popen thinks process is still alive (just like pexpect) - very strange behavior
- # so for now progress can not be determined correctly
p = self.call_unrar(command, self.file, self.out, password=password)
renice(p.pid, self.renice)
progress(0)
- out, err = p.communicate() #wait for process
+ progressstring = ""
+ while True:
+ c = p.stdout.read(1)
+ # quit loop on eof
+ if not c:
+ break
+ # reading a percentage sign -> set progress and restart
+ if c == '%':
+ progress(int(progressstring))
+ progressstring = ""
+ # not reading a digit -> therefore restart
+ elif c not in digits:
+ progressstring = ""
+ # add digit to progressstring
+ else:
+ progressstring = progressstring + c
progress(100)
+ # retrieve stderr
+ err = p.stderr.read()
+
if "CRC failed" in err and not password and not self.passwordProtected:
raise CRCError
elif "CRC failed" in err:
@@ -139,7 +157,9 @@ class UnRar(AbtractExtractor):
def getDeleteFiles(self):
if ".part" in self.file:
return glob(re.sub("(?<=\.part)([01]+)", "*", self.file, re.IGNORECASE))
- return [self.file]
+ # get files which matches .r* and filter unsuited files out
+ parts = glob(re.sub(r"(?<=\.r)ar$", "*", self.file, re.IGNORECASE))
+ return filter(lambda x: self.re_partfiles.match(x), parts)
def listContent(self):
command = "vb" if self.fullpath else "lb"