Skip to content

Commit

Permalink
fix in fedora: 7z doesn't support rar archives, use unrar (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlicesReflexion committed Jan 21, 2023
1 parent c979486 commit 4fa7278
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kindlecomicconverter/comicarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ def __init__(self, filepath):
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.')

Expand All @@ -50,7 +57,11 @@ def extract(self, targetdir):
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')
Expand Down

0 comments on commit 4fa7278

Please sign in to comment.