mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 18:47:09 -07:00
add par2 rename/repair (linux only). Fixes #1306
This commit is contained in:
parent
36e5b4d453
commit
3996147fb4
2 changed files with 49 additions and 2 deletions
|
@ -195,6 +195,7 @@ OUTPUTFASTSTART = None
|
|||
OUTPUTQUALITYPERCENT = None
|
||||
FFMPEG = None
|
||||
SEVENZIP = None
|
||||
PAR2CMD = None
|
||||
FFPROBE = None
|
||||
CHECK_MEDIA = None
|
||||
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, \
|
||||
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, \
|
||||
PLEXSSL, PLEXHOST, PLEXPORT, PLEXTOKEN, PLEXSEC, TORRENT_RESUME
|
||||
PLEXSSL, PLEXHOST, PLEXPORT, PLEXTOKEN, PLEXSEC, TORRENT_RESUME, PAR2CMD
|
||||
|
||||
if __INITIALIZED__:
|
||||
return False
|
||||
|
@ -760,7 +761,15 @@ def initialize(section=None):
|
|||
if not SEVENZIP:
|
||||
SEVENZIP = None
|
||||
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'),
|
||||
os.X_OK):
|
||||
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg')
|
||||
|
|
|
@ -3,6 +3,8 @@ import os
|
|||
import re
|
||||
import core
|
||||
import shlex
|
||||
import platform
|
||||
import subprocess
|
||||
from core import logger
|
||||
from core.nzbToMediaUtil import listMediaFiles
|
||||
|
||||
|
@ -26,6 +28,7 @@ char_replace = [[r"(\w)1\.(\w)", r"\1i\2"]
|
|||
|
||||
|
||||
def process_all_exceptions(name, dirname):
|
||||
par2(dirname)
|
||||
rename_script(dirname)
|
||||
for filename in listMediaFiles(dirname):
|
||||
newfilename = None
|
||||
|
@ -141,6 +144,41 @@ def rename_script(dirname):
|
|||
except Exception as error:
|
||||
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
|
||||
# we can add more to this list
|
||||
# _customgroups = {'Q o Q': process_qoq, '-ECI': process_eci}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue