Fixes issues with extracting and linking of archives.

Fixes other issues from previous update.
This commit is contained in:
echel0n 2014-04-24 23:41:26 -07:00
commit f5f0ff6e10
7 changed files with 64 additions and 51 deletions

View file

@ -312,7 +312,7 @@ def main(args):
# Perform Manual Post-Processing # Perform Manual Post-Processing
logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...") logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...")
for section, subsection in nzbtomedia.SUBSECTIONS.items(): for section, subsection in nzbtomedia.SECTIONS.items():
for category in subsection: for category in subsection:
for dirName in nzbtomedia.getDirs(subsection[category]): for dirName in nzbtomedia.getDirs(subsection[category]):
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName)) logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName))
@ -341,7 +341,7 @@ def main(args):
except: except:
inputID = None inputID = None
if not clientAgent.lower() in (nzbtomedia.TORRENT_CLIENTS or 'manual'): if not clientAgent.lower() in (nzbtomedia.TORRENT_CLIENTS,'manual'):
continue continue
results = processTorrent(dirName, os.path.basename(dirName), category, inputHash, inputID, results = processTorrent(dirName, os.path.basename(dirName), category, inputHash, inputID,

View file

@ -460,7 +460,7 @@ def main(args, section=None):
# Perform Manual Post-Processing # Perform Manual Post-Processing
logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...") logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...")
for section, subsection in nzbtomedia.SUBSECTIONS.items(): for section, subsection in nzbtomedia.SECTIONS.items():
for category in subsection: for category in subsection:
for dirName in getDirs(subsection[category]): for dirName in getDirs(subsection[category]):
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName)) logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName))

View file

@ -1,5 +1,6 @@
import locale import locale
import os import os
import re
import subprocess import subprocess
import sys import sys
import platform import platform
@ -111,7 +112,6 @@ MINSAMPLESIZE = None
SAMPLEIDS = None SAMPLEIDS = None
SECTIONS = [] SECTIONS = []
SUBSECTIONS = {}
TRANSCODE = None TRANSCODE = None
FFMPEG_PATH = None FFMPEG_PATH = None
@ -140,8 +140,9 @@ USER_SCRIPT_CLEAN = None
USER_DELAY = None USER_DELAY = None
USER_SCRIPT_RUNONCE = None USER_SCRIPT_RUNONCE = None
__INITIALIZED__ = False PASSWORDSFILE = None
__INITIALIZED__ = False
def initialize(section=None): def initialize(section=None):
global NZBGET_POSTPROCESS_ERROR, NZBGET_POSTPROCESS_NONE, NZBGET_POSTPROCESS_PARCHECK, NZBGET_POSTPROCESS_SUCCESS, \ global NZBGET_POSTPROCESS_ERROR, NZBGET_POSTPROCESS_NONE, NZBGET_POSTPROCESS_PARCHECK, NZBGET_POSTPROCESS_SUCCESS, \
@ -150,12 +151,13 @@ def initialize(section=None):
SABNZB_NO_OF_ARGUMENTS, SABNZB_0717_NO_OF_ARGUMENTS, CATEGORIES, TORRENT_CLIENTAGENT, USELINK, OUTPUTDIRECTORY, NOFLATTEN, \ SABNZB_NO_OF_ARGUMENTS, SABNZB_0717_NO_OF_ARGUMENTS, CATEGORIES, TORRENT_CLIENTAGENT, USELINK, OUTPUTDIRECTORY, NOFLATTEN, \
UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, TRANSMISSIONHOST, TRANSMISSIONPORT, \ UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, TRANSMISSIONHOST, TRANSMISSIONPORT, \
TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, MINSAMPLESIZE, SAMPLEIDS, \ TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, METACONTAINER, MINSAMPLESIZE, SAMPLEIDS, \
SECTIONS, SUBSECTIONS, USER_SCRIPT_CATEGORIES, __INITIALIZED__, AUTO_UPDATE, APP_FILENAME, USER_DELAY, USER_SCRIPT_RUNONCE, \ SECTIONS, USER_SCRIPT_CATEGORIES, __INITIALIZED__, AUTO_UPDATE, APP_FILENAME, USER_DELAY, USER_SCRIPT_RUNONCE, \
APP_NAME, USER_SCRIPT_MEDIAEXTENSIONS, USER_SCRIPT, USER_SCRIPT_PARAM, USER_SCRIPT_SUCCESSCODES, USER_SCRIPT_CLEAN, \ APP_NAME, USER_SCRIPT_MEDIAEXTENSIONS, USER_SCRIPT, USER_SCRIPT_PARAM, USER_SCRIPT_SUCCESSCODES, USER_SCRIPT_CLEAN, \
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \ TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, LOG_DB, \ DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, LOG_DB, \
OUTPUTVIDEOBITRATE, OUTPUTAUDIOCODEC, OUTPUTAUDIOBITRATE, OUTPUTSUBTITLECODEC, OUTPUTFASTSTART, OUTPUTQUALITYPERCENT, \ OUTPUTVIDEOBITRATE, OUTPUTAUDIOCODEC, OUTPUTAUDIOBITRATE, OUTPUTSUBTITLECODEC, OUTPUTFASTSTART, OUTPUTQUALITYPERCENT, \
NICENESS, LOG_DEBUG, FORCE_CLEAN, FFMPEG_PATH, FFMPEG, FFPROBE, AUDIOCONTAINER, EXTCONTAINER, TORRENT_CLASS, DELETE_ORIGINAL NICENESS, LOG_DEBUG, FORCE_CLEAN, FFMPEG_PATH, FFMPEG, FFPROBE, AUDIOCONTAINER, EXTCONTAINER, TORRENT_CLASS, DELETE_ORIGINAL,\
PASSWORDSFILE
if __INITIALIZED__: if __INITIALIZED__:
return False return False
@ -263,7 +265,10 @@ def initialize(section=None):
DELUGEUSR = CFG["Torrent"]["DelugeUSR"] # mysecretusr DELUGEUSR = CFG["Torrent"]["DelugeUSR"] # mysecretusr
DELUGEPWD = CFG["Torrent"]["DelugePWD"] # mysecretpwr DELUGEPWD = CFG["Torrent"]["DelugePWD"] # mysecretpwr
COMPRESSEDCONTAINER = CFG["Extensions"]["compressedExtensions"] COMPRESSEDCONTAINER = [re.compile('.r\d{2}$', re.I),
re.compile('.part\d+.rar$', re.I),
re.compile('.rar$', re.I)]
COMPRESSEDCONTAINER += [re.compile('%s$' % ext, re.I) for ext in CFG["Extensions"]["compressedExtensions"]]
MEDIACONTAINER = CFG["Extensions"]["mediaExtensions"] MEDIACONTAINER = CFG["Extensions"]["mediaExtensions"]
AUDIOCONTAINER = CFG["Extensions"]["audioExtensions"] AUDIOCONTAINER = CFG["Extensions"]["audioExtensions"]
METACONTAINER = CFG["Extensions"]["metaExtensions"] # .nfo,.sub,.srt METACONTAINER = CFG["Extensions"]["metaExtensions"] # .nfo,.sub,.srt
@ -287,6 +292,8 @@ def initialize(section=None):
OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"]) OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"])
NICENESS = int(CFG["Transcoder"]["niceness"]) NICENESS = int(CFG["Transcoder"]["niceness"])
PASSWORDSFILE = CFG["passwords"]["PassWordFile"]
# Setup FFMPEG and FFPROBE locations # Setup FFMPEG and FFPROBE locations
if platform.system() == 'Windows': if platform.system() == 'Windows':
FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg.exe') FFMPEG = os.path.join(FFMPEG_PATH, 'ffmpeg.exe')
@ -327,9 +334,9 @@ def initialize(section=None):
USER_SCRIPT_RUNONCE = int(CFG["UserScript"]["user_script_runOnce"]) USER_SCRIPT_RUNONCE = int(CFG["UserScript"]["user_script_runOnce"])
# check for script-defied section and if None set to allow sections # check for script-defied section and if None set to allow sections
SECTIONS = tuple(x for x in CFG if CFG[x].sections) if not section else (section,) SECTIONS = CFG[tuple(x for x in CFG if CFG[x].sections) if not section else (section,)]
SUBSECTIONS = CFG[SECTIONS].isenabled() map(CATEGORIES.extend,([subsection.sections for section,subsection in SECTIONS.items()]))
CATEGORIES += SUBSECTIONS.sections CATEGORIES = list(set(CATEGORIES))
# create torrent class # create torrent class
TORRENT_CLASS = create_torrent_class(TORRENT_CLIENTAGENT) TORRENT_CLASS = create_torrent_class(TORRENT_CLIENTAGENT)

View file

@ -72,9 +72,8 @@ def extract(filePath, outputDestination):
# Create outputDestination folder # Create outputDestination folder
nzbtomedia.makeDir(outputDestination) nzbtomedia.makeDir(outputDestination)
passwordsfile = nzbtomedia.CFG["passwords"]["PassWordFile"] if nzbtomedia.PASSWORDSFILE != "" and os.path.isfile(os.path.normpath(nzbtomedia.PASSWORDSFILE)):
if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)): passwords = [line.strip() for line in open(os.path.normpath(nzbtomedia.PASSWORDSFILE))]
passwords = [line.strip() for line in open(os.path.normpath(passwordsfile))]
else: else:
passwords = [] passwords = []
nzbtomedia.logger.info("Extracting %s to %s" % (filePath, outputDestination)) nzbtomedia.logger.info("Extracting %s to %s" % (filePath, outputDestination))

View file

@ -39,9 +39,12 @@ class Section(configobj.Section):
if section in key: if section in key:
continue continue
if isinstance(subsections, Section) and subsections.sections: if isinstance(subsections, Section) and subsections.sections:
for subsection in subsections: for subsection, options in subsections.items():
if subsection in key: if subsection in key:
continue continue
if key in options:
return options[key]
subsections.pop(subsection) subsections.pop(subsection)
else: else:
if section not in key: if section not in key:

View file

@ -459,11 +459,9 @@ def rmDir(dirName):
def cleanProcDirs(): def cleanProcDirs():
logger.info('Cleaning processing directories ...', 'CLEANDIRS') logger.info('Cleaning processing directories ...', 'CLEANDIRS')
for section, subsection in nzbtomedia.SUBSECTIONS.items(): for section, subsection in nzbtomedia.SECTIONS.items():
for category in subsection: for category in subsection:
if nzbtomedia.CFG[section][category].isenabled(): for dirName in nzbtomedia.getDirs(subsection[category]):
dirNames = getDirs(section, category)
for dirName in dirNames:
try: try:
minSize = int(nzbtomedia.CFG[section][category]['minSize']) minSize = int(nzbtomedia.CFG[section][category]['minSize'])
except:minSize = 0 except:minSize = 0
@ -603,6 +601,14 @@ def cleanFileName(filename):
filename = re.sub("^\[.*\]", "", filename) filename = re.sub("^\[.*\]", "", filename)
return filename.strip() return filename.strip()
def is_archive_file(filename):
"""Check if the filename is allowed for the Archive"""
for regext in nzbtomedia.COMPRESSEDCONTAINER:
if regext.search(filename):
return regext.split(filename)[0]
return False
def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True): def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
fileName, fileExt = os.path.splitext(mediafile) fileName, fileExt = os.path.splitext(mediafile)
@ -613,7 +619,7 @@ def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
if (media and fileExt.lower() in nzbtomedia.MEDIACONTAINER)\ if (media and fileExt.lower() in nzbtomedia.MEDIACONTAINER)\
or (audio and fileExt.lower() in nzbtomedia.AUDIOCONTAINER)\ or (audio and fileExt.lower() in nzbtomedia.AUDIOCONTAINER)\
or (meta and fileExt.lower() in nzbtomedia.METACONTAINER)\ or (meta and fileExt.lower() in nzbtomedia.METACONTAINER)\
or (archives and fileExt.lower() in nzbtomedia.COMPRESSEDCONTAINER): or (archives and is_archive_file(mediafile)):
return True return True
else: else:
return False return False
@ -696,33 +702,25 @@ def find_imdbid(dirName, inputName):
def extractFiles(src, dst=None): def extractFiles(src, dst=None):
extracted_folder = [] extracted_folder = []
for inputFile in listMediaFiles(src): for inputFile in listMediaFiles(src, media=False, audio=False, meta=False, archives=True):
dirPath = os.path.dirname(inputFile) dirPath = os.path.dirname(inputFile)
fileName, fileExt = os.path.splitext(os.path.basename(inputFile))
fullFileName = os.path.basename(inputFile) fullFileName = os.path.basename(inputFile)
if fileExt in nzbtomedia.COMPRESSEDCONTAINER: if dirPath in extracted_folder:
if re.search('part\d+', fullFileName):
if not re.search('^((?!\.part(?!0*1\.rar$)\d+\.rar$).)*\.(?:rar|r?0*1)$', fullFileName):
continue
logger.info("Found compressed archive %s for file %s" % (fileExt, fullFileName))
while(True):
try:
extractor.extract(inputFile, dst or dirPath)
extracted_folder.append(dst or dirPath)
break break
except:
try:
if extractor.extract(inputFile, dirPath or dst):
extracted_folder.append(dirPath or dst)
except Exception, e:
logger.error("Extraction failed for: %s" % (fullFileName)) logger.error("Extraction failed for: %s" % (fullFileName))
if extracted_folder: if extracted_folder:
for folder in extracted_folder: for folder in extracted_folder:
for inputFile in listMediaFiles(folder): for inputFile in listMediaFiles(folder):
fullFileName = os.path.basename(inputFile) fullFileName = os.path.basename(inputFile)
fileName, fileExt = os.path.splitext(fullFileName)
if fileExt in nzbtomedia.COMPRESSEDCONTAINER: if is_archive_file(inputFile):
logger.info("Removing extracted archive %s from folder %s ..." % (fullFileName, folder)) logger.info("Removing extracted archive %s from folder %s ..." % (fullFileName, folder))
try: try:
os.remove(inputFile) os.remove(inputFile)

View file

@ -1,5 +1,6 @@
import os import os
import datetime import datetime
import re
import nzbtomedia import nzbtomedia
from nzbtomedia import nzbToMediaDB from nzbtomedia import nzbToMediaDB
from nzbtomedia.nzbToMediaUtil import get_downloadInfo from nzbtomedia.nzbToMediaUtil import get_downloadInfo
@ -7,6 +8,11 @@ from nzbtomedia.nzbToMediaUtil import get_downloadInfo
# Initialize the config # Initialize the config
nzbtomedia.initialize() nzbtomedia.initialize()
EXTENSIONS = [re.compile('.r\d{2}$', re.I),
re.compile('.part\d+.rar$', re.I),
re.compile('.rar$', re.I)]
EXTENSIONS += [re.compile('%s$' % ext, re.I) for ext in nzbtomedia.COMPRESSEDCONTAINER]
test = nzbtomedia.CFG['HeadPhones']['music'] test = nzbtomedia.CFG['HeadPhones']['music']
section = nzbtomedia.CFG.findsection('tv').isenabled() section = nzbtomedia.CFG.findsection('tv').isenabled()
print section print section