add par2 rename/repair (linux only). Fixes #1306

This commit is contained in:
clinton-hall 2017-12-09 08:40:26 +13:00
commit 3996147fb4
2 changed files with 49 additions and 2 deletions

View file

@ -195,6 +195,7 @@ OUTPUTFASTSTART = None
OUTPUTQUALITYPERCENT = None OUTPUTQUALITYPERCENT = None
FFMPEG = None FFMPEG = None
SEVENZIP = None SEVENZIP = None
PAR2CMD = None
FFPROBE = None FFPROBE = None
CHECK_MEDIA = None CHECK_MEDIA = None
NICENESS = [] NICENESS = []
@ -233,7 +234,7 @@ def initialize(section=None):
DELETE_ORIGINAL, TORRENT_CHMOD_DIRECTORY, PASSWORDSFILE, USER_DELAY, USER_SCRIPT, USER_SCRIPT_CLEAN, USER_SCRIPT_MEDIAEXTENSIONS, \ DELETE_ORIGINAL, TORRENT_CHMOD_DIRECTORY, PASSWORDSFILE, USER_DELAY, USER_SCRIPT, USER_SCRIPT_CLEAN, USER_SCRIPT_MEDIAEXTENSIONS, \
USER_SCRIPT_PARAM, USER_SCRIPT_RUNONCE, USER_SCRIPT_SUCCESSCODES, DOWNLOADINFO, CHECK_MEDIA, SAFE_MODE, \ USER_SCRIPT_PARAM, USER_SCRIPT_RUNONCE, USER_SCRIPT_SUCCESSCODES, DOWNLOADINFO, CHECK_MEDIA, SAFE_MODE, \
TORRENT_DEFAULTDIR, TORRENT_RESUME_ON_FAILURE, NZB_DEFAULTDIR, REMOTEPATHS, LOG_ENV, PID_FILE, MYAPP, ACHANNELS, ACHANNELS2, ACHANNELS3, \ TORRENT_DEFAULTDIR, TORRENT_RESUME_ON_FAILURE, NZB_DEFAULTDIR, REMOTEPATHS, LOG_ENV, PID_FILE, MYAPP, ACHANNELS, ACHANNELS2, ACHANNELS3, \
PLEXSSL, PLEXHOST, PLEXPORT, PLEXTOKEN, PLEXSEC, TORRENT_RESUME PLEXSSL, PLEXHOST, PLEXPORT, PLEXTOKEN, PLEXSEC, TORRENT_RESUME, PAR2CMD
if __INITIALIZED__: if __INITIALIZED__:
return False return False
@ -760,7 +761,15 @@ def initialize(section=None):
if not SEVENZIP: if not SEVENZIP:
SEVENZIP = None SEVENZIP = None
logger.warning( logger.warning(
"Failed to locate 7zip. Transcosing of disk images and extraction of .7z files will not be possible!") "Failed to locate 7zip. Transcoding of disk images and extraction of .7z files will not be possible!")
try:
PAR2CMD = subprocess.Popen(['which', 'par2'], stdout=subprocess.PIPE).communicate()[0].strip()
except:
pass
if not PAR2CMD:
PAR2CMD = None
logger.warning(
"Failed to locate par2. Repair and rename using par files will not be possible!")
if os.path.isfile(os.path.join(FFMPEG_PATH, 'ffmpeg')) or os.access(os.path.join(FFMPEG_PATH, 'ffmpeg'), if os.path.isfile(os.path.join(FFMPEG_PATH, 'ffmpeg')) or os.access(os.path.join(FFMPEG_PATH, 'ffmpeg'),
os.X_OK): os.X_OK):
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg') FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg')

View file

@ -3,6 +3,8 @@ import os
import re import re
import core import core
import shlex import shlex
import platform
import subprocess
from core import logger from core import logger
from core.nzbToMediaUtil import listMediaFiles from core.nzbToMediaUtil import listMediaFiles
@ -26,6 +28,7 @@ char_replace = [[r"(\w)1\.(\w)", r"\1i\2"]
def process_all_exceptions(name, dirname): def process_all_exceptions(name, dirname):
par2(dirname)
rename_script(dirname) rename_script(dirname)
for filename in listMediaFiles(dirname): for filename in listMediaFiles(dirname):
newfilename = None newfilename = None
@ -141,6 +144,41 @@ def rename_script(dirname):
except Exception as error: except Exception as error:
logger.error("Unable to rename file due to: {error}".format(error=error), "EXCEPTION") logger.error("Unable to rename file due to: {error}".format(error=error), "EXCEPTION")
def par2(dirname):
newlist = []
sofar = 0
parfile = ""
objects = os.listdir(dirname)
for item in objects:
if item.endswith(".par2"):
size = os.path.getsize(item)
if size > sofar:
sofar = size
parfile = item
if core.PAR2CMD and parfile:
pwd = os.getcwd() # Get our Present Working Directory
os.chdir(dirname) # set directory to run par on.
if platform.system() == 'Windows':
bitbucket = open('NUL')
else:
bitbucket = open('/dev/null')
logger.info("Running par2 on file {0}.".format(parfile), "PAR2")
command = [core.PAR2CMD, 'r', parfile, "*"]
cmd = ""
for item in command:
cmd = "{cmd} {item}".format(cmd=cmd, item=item)
logger.debug("calling command:{0}".format(cmd), "PAR2")
try:
proc = subprocess.Popen(command, stdout=bitbucket, stderr=bitbucket)
proc.communicate()
result = proc.returncode
except:
logger.error("par2 file processing for {0} has failed".format(parfile), "PAR2")
if result == 0:
logger.info("par2 file processing succeeded", "PAR2")
os.chdir(pwd)
bitbucket.close()
# dict for custom groups # dict for custom groups
# we can add more to this list # we can add more to this list
# _customgroups = {'Q o Q': process_qoq, '-ECI': process_eci} # _customgroups = {'Q o Q': process_qoq, '-ECI': process_eci}