From 4fa72780a11907d094b56444ad60492adc791aa6 Mon Sep 17 00:00:00 2001 From: Alice Charatonik <6933425+AlicesReflexion@users.noreply.github.com> Date: Sat, 21 Jan 2023 03:54:11 -0600 Subject: [PATCH] fix in fedora: 7z doesn't support rar archives, use unrar (#370) see https://github.com/ttys3/fedora-rpm-p7zip https://sourceforge.net/p/sevenzip/discussion/45798/thread/dc2d0438/#8f9f --- kindlecomicconverter/comicarchive.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kindlecomicconverter/comicarchive.py b/kindlecomicconverter/comicarchive.py index 2235a42..dcaec36 100644 --- a/kindlecomicconverter/comicarchive.py +++ b/kindlecomicconverter/comicarchive.py @@ -39,7 +39,14 @@ class ComicArchive: break process.communicate() if process.returncode != 0: - raise OSError('Archive is corrupted or encrypted.') + process = Popen('unrar l -y -p1 "' + self.filepath + '"', stderr=STDOUT, stdout=PIPE, stdin=PIPE, shell=True) + for line in process.stdout: + if b'Details: ' in line: + self.type = line.rstrip().decode().split(' ')[1].upper() + print(self.type) + break + if(self.type != 'RAR'): + raise OSError('Archive is corrupted or encrypted.') elif self.type not in ['7Z', 'RAR', 'RAR5', 'ZIP']: raise OSError('Unsupported archive format.') @@ -50,7 +57,11 @@ class ComicArchive: self.filepath + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True) process.communicate() if process.returncode != 0: - raise OSError('Failed to extract archive.') + process = Popen('unrar x -y -x__MACOSX -x.DS_Store -xthumbs.db -xThumbs.db "' + self.filepath + '" "' + + targetdir + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True) + process.communicate() + if process.returncode != 0: + raise OSError('Failed to extract archive.') tdir = os.listdir(targetdir) if 'ComicInfo.xml' in tdir: tdir.remove('ComicInfo.xml')