1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 17:56:30 +00:00

Merge pull request #515 from darodi/unrar_for_fedora

use unrar for fedora only
This commit is contained in:
darodi
2023-05-13 16:25:06 +00:00
committed by GitHub
3 changed files with 12 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ On Debian based distributions these two commands should install all needed depen
```bash ```bash
$ sudo apt-get install -y python3 python3-dev libpng-dev libjpeg-dev p7zip-full unrar-free libgl1 python3-pyqt5 && \ $ sudo apt-get install -y python3 python3-dev libpng-dev libjpeg-dev p7zip-full p7zip-rar unrar-free libgl1 python3-pyqt5 && \
python -m pip install --upgrade pip && \ python -m pip install --upgrade pip && \
python -m pip install --upgrade -r requirements.txt python -m pip install --upgrade -r requirements.txt
``` ```

View File

@@ -19,6 +19,7 @@
# #
import os import os
import distro
from psutil import Popen from psutil import Popen
from shutil import move from shutil import move
from subprocess import STDOUT, PIPE from subprocess import STDOUT, PIPE
@@ -38,17 +39,19 @@ class ComicArchive:
self.type = line.rstrip().decode().split(' = ')[1].upper() self.type = line.rstrip().decode().split(' = ')[1].upper()
break break
process.communicate() process.communicate()
if process.returncode != 0: if process.returncode != 0 and distro.id() == 'fedora':
process = Popen('unrar l -y -p1 "' + self.filepath + '"', stderr=STDOUT, stdout=PIPE, stdin=PIPE, shell=True) process = Popen('unrar l -y -p1 "' + self.filepath + '"', stderr=STDOUT, stdout=PIPE, stdin=PIPE, shell=True)
for line in process.stdout: for line in process.stdout:
if b'Details: ' in line: if b'Details: ' in line:
self.type = line.rstrip().decode().split(' ')[1].upper() self.type = line.rstrip().decode().split(' ')[1].upper()
print(self.type)
break break
if(self.type != 'RAR'): process.communicate()
if process.returncode != 0:
raise OSError('Archive is corrupted or encrypted.') raise OSError('Archive is corrupted or encrypted.')
elif self.type not in ['7Z', 'RAR', 'RAR5', 'ZIP']: elif self.type not in ['7Z', 'RAR', 'RAR5', 'ZIP']:
raise OSError('Unsupported archive format.') raise OSError('Unsupported archive format.')
elif self.type not in ['7Z', 'RAR', 'RAR5', 'ZIP']:
raise OSError('Unsupported archive format.')
def extract(self, targetdir): def extract(self, targetdir):
if not os.path.isdir(targetdir): if not os.path.isdir(targetdir):
@@ -56,12 +59,14 @@ class ComicArchive:
process = Popen('7z x -y -xr!__MACOSX -xr!.DS_Store -xr!thumbs.db -xr!Thumbs.db -o"' + targetdir + '" "' + process = Popen('7z x -y -xr!__MACOSX -xr!.DS_Store -xr!thumbs.db -xr!Thumbs.db -o"' + targetdir + '" "' +
self.filepath + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True) self.filepath + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
process.communicate() process.communicate()
if process.returncode != 0: if process.returncode != 0 and distro.id() == 'fedora':
process = Popen('unrar x -y -x__MACOSX -x.DS_Store -xthumbs.db -xThumbs.db "' + self.filepath + '" "' + 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) targetdir + '"', stdout=PIPE, stderr=STDOUT, stdin=PIPE, shell=True)
process.communicate() process.communicate()
if process.returncode != 0: if process.returncode != 0:
raise OSError('Failed to extract archive.') raise OSError('Failed to extract archive.')
elif process.returncode != 0:
raise OSError('Failed to extract archive. Check if p7zip-rar is installed.')
tdir = os.listdir(targetdir) tdir = os.listdir(targetdir)
if 'ComicInfo.xml' in tdir: if 'ComicInfo.xml' in tdir:
tdir.remove('ComicInfo.xml') tdir.remove('ComicInfo.xml')

View File

@@ -5,3 +5,4 @@ python-slugify>=1.2.1
raven>=6.0.0 raven>=6.0.0
# PyQt5-tools # PyQt5-tools
mozjpeg-lossless-optimization>=1.1.2 mozjpeg-lossless-optimization>=1.1.2
distro