mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-01 12:32:25 +08:00
Added support for unar RAR extraction utility. #1833
This commit is contained in:
parent
3d7fa06f41
commit
642733f92f
4 changed files with 41 additions and 21 deletions
|
@ -2,18 +2,20 @@
|
|||
|
||||
import os
|
||||
import io
|
||||
import rarfile
|
||||
import sys
|
||||
import subprocess
|
||||
import subliminal
|
||||
import datetime
|
||||
import time
|
||||
import rarfile
|
||||
|
||||
from dogpile.cache.region import register_backend as register_cache_backend
|
||||
|
||||
from app.config import settings, configure_captcha_func
|
||||
from app.database import init_db, migrate_db
|
||||
from app.get_args import args
|
||||
from app.logger import configure_logging
|
||||
from utilities.binaries import get_binary, BinaryNotFound
|
||||
from utilities.path_mappings import path_mappings
|
||||
from utilities.backup import restore_from_backup
|
||||
|
||||
|
@ -193,23 +195,28 @@ with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'config.ini')
|
|||
|
||||
|
||||
def init_binaries():
|
||||
from utilities.binaries import get_binary
|
||||
exe = get_binary("unrar")
|
||||
|
||||
rarfile.UNRAR_TOOL = exe
|
||||
rarfile.ORIG_UNRAR_TOOL = exe
|
||||
try:
|
||||
rarfile.custom_check([rarfile.UNRAR_TOOL], True)
|
||||
except Exception:
|
||||
logging.debug("custom check failed for: %s", exe)
|
||||
|
||||
logging.debug("Using UnRAR from: %s", exe)
|
||||
unrar = exe
|
||||
|
||||
return unrar
|
||||
exe = get_binary("unar")
|
||||
rarfile.UNAR_TOOL = exe
|
||||
rarfile.UNRAR_TOOL = None
|
||||
rarfile.tool_setup(unrar=False, unar=True, bsdtar=False, force=True)
|
||||
except (BinaryNotFound, rarfile.RarCannotExec):
|
||||
try:
|
||||
exe = get_binary("unrar")
|
||||
rarfile.UNRAR_TOOL = exe
|
||||
rarfile.UNAR_TOOL = None
|
||||
rarfile.tool_setup(unrar=True, unar=False, bsdtar=False, force=True)
|
||||
except (BinaryNotFound, rarfile.RarCannotExec):
|
||||
logging.exception("BAZARR requires a rar archive extraction utilities (unrar, unar) and it can't be found.")
|
||||
raise BinaryNotFound
|
||||
else:
|
||||
logging.debug("Using UnRAR from: %s", exe)
|
||||
return exe
|
||||
else:
|
||||
logging.debug("Using unar from: %s", exe)
|
||||
return exe
|
||||
|
||||
|
||||
from app.database import init_db, migrate_db # noqa E402
|
||||
init_db()
|
||||
migrate_db()
|
||||
init_binaries()
|
||||
|
|
|
@ -171,9 +171,9 @@ class LegendasTVProvider(Provider):
|
|||
|
||||
# Provider needs UNRAR installed. If not available raise ConfigurationError
|
||||
try:
|
||||
rarfile.custom_check(rarfile.UNRAR_TOOL)
|
||||
except rarfile.RarExecError:
|
||||
raise ConfigurationError('UNRAR tool not available')
|
||||
rarfile.tool_setup()
|
||||
except rarfile.RarCannotExec:
|
||||
raise ConfigurationError('RAR extraction tool not available')
|
||||
|
||||
if any((username, password)) and not all((username, password)):
|
||||
raise ConfigurationError('Username and password must be specified')
|
||||
|
|
|
@ -78,8 +78,8 @@ class LegendasTVProvider(_LegendasTVProvider):
|
|||
# Provider needs UNRAR installed. If not available raise ConfigurationError
|
||||
try:
|
||||
rarfile.tool_setup()
|
||||
except rarfile.RarExecError:
|
||||
raise ConfigurationError('UNRAR tool not available')
|
||||
except rarfile.RarCannotExec:
|
||||
raise ConfigurationError('RAR extraction tool not available')
|
||||
|
||||
if any((username, password)) and not all((username, password)):
|
||||
raise ConfigurationError('Username and password must be specified')
|
||||
|
|
|
@ -15,7 +15,20 @@ class RarFile(rarfile.RarFile):
|
|||
:param psw:
|
||||
:return:
|
||||
"""
|
||||
cmd = [rarfile.UNRAR_TOOL] + list(rarfile.ORIG_OPEN_ARGS)
|
||||
exe = None
|
||||
try:
|
||||
rarfile.tool_setup(unrar=False, unar=True, bsdtar=False, force=True)
|
||||
except rarfile.RarCannotExec:
|
||||
try:
|
||||
rarfile.rarfile.tool_setup(unrar=True, unar=False, bsdtar=False, force=True)
|
||||
except rarfile.RarCannotExec:
|
||||
raise rarfile.RarCannotExec
|
||||
else:
|
||||
exe = rarfile.UNRAR_TOOL
|
||||
else:
|
||||
exe = rarfile.UNAR_TOOL
|
||||
finally:
|
||||
cmd = [exe] + list(rarfile.ORIG_OPEN_ARGS)
|
||||
|
||||
with rarfile.XTempFile(self._rarfile) as rf:
|
||||
log.debug(u"RAR CMD: %s", cmd + [rf, fname])
|
||||
|
|
Loading…
Reference in a new issue