mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Fixes issues with extracting and linking of archives.
Fixes other issues from previous update.
This commit is contained in:
parent
289d451112
commit
f5f0ff6e10
7 changed files with 64 additions and 51 deletions
|
@ -312,7 +312,7 @@ def main(args):
|
|||
# Perform Manual Post-Processing
|
||||
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 dirName in nzbtomedia.getDirs(subsection[category]):
|
||||
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName))
|
||||
|
@ -341,7 +341,7 @@ def main(args):
|
|||
except:
|
||||
inputID = None
|
||||
|
||||
if not clientAgent.lower() in (nzbtomedia.TORRENT_CLIENTS or 'manual'):
|
||||
if not clientAgent.lower() in (nzbtomedia.TORRENT_CLIENTS,'manual'):
|
||||
continue
|
||||
|
||||
results = processTorrent(dirName, os.path.basename(dirName), category, inputHash, inputID,
|
||||
|
|
|
@ -460,7 +460,7 @@ def main(args, section=None):
|
|||
# Perform Manual Post-Processing
|
||||
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 dirName in getDirs(subsection[category]):
|
||||
logger.info("Starting manual run for %s:%s - Folder:%s" % (section, category, dirName))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import locale
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import platform
|
||||
|
@ -111,7 +112,6 @@ MINSAMPLESIZE = None
|
|||
SAMPLEIDS = None
|
||||
|
||||
SECTIONS = []
|
||||
SUBSECTIONS = {}
|
||||
|
||||
TRANSCODE = None
|
||||
FFMPEG_PATH = None
|
||||
|
@ -140,8 +140,9 @@ USER_SCRIPT_CLEAN = None
|
|||
USER_DELAY = None
|
||||
USER_SCRIPT_RUNONCE = None
|
||||
|
||||
__INITIALIZED__ = False
|
||||
PASSWORDSFILE = None
|
||||
|
||||
__INITIALIZED__ = False
|
||||
|
||||
def initialize(section=None):
|
||||
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, \
|
||||
UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, TRANSMISSIONHOST, TRANSMISSIONPORT, \
|
||||
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, \
|
||||
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
|
||||
DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, LOG_DB, \
|
||||
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__:
|
||||
return False
|
||||
|
@ -263,7 +265,10 @@ def initialize(section=None):
|
|||
DELUGEUSR = CFG["Torrent"]["DelugeUSR"] # mysecretusr
|
||||
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"]
|
||||
AUDIOCONTAINER = CFG["Extensions"]["audioExtensions"]
|
||||
METACONTAINER = CFG["Extensions"]["metaExtensions"] # .nfo,.sub,.srt
|
||||
|
@ -287,6 +292,8 @@ def initialize(section=None):
|
|||
OUTPUTQUALITYPERCENT = int(CFG["Transcoder"]["outputQualityPercent"])
|
||||
NICENESS = int(CFG["Transcoder"]["niceness"])
|
||||
|
||||
PASSWORDSFILE = CFG["passwords"]["PassWordFile"]
|
||||
|
||||
# Setup FFMPEG and FFPROBE locations
|
||||
if platform.system() == 'Windows':
|
||||
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"])
|
||||
|
||||
# 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,)
|
||||
SUBSECTIONS = CFG[SECTIONS].isenabled()
|
||||
CATEGORIES += SUBSECTIONS.sections
|
||||
SECTIONS = CFG[tuple(x for x in CFG if CFG[x].sections) if not section else (section,)]
|
||||
map(CATEGORIES.extend,([subsection.sections for section,subsection in SECTIONS.items()]))
|
||||
CATEGORIES = list(set(CATEGORIES))
|
||||
|
||||
# create torrent class
|
||||
TORRENT_CLASS = create_torrent_class(TORRENT_CLIENTAGENT)
|
||||
|
|
|
@ -72,9 +72,8 @@ def extract(filePath, outputDestination):
|
|||
# Create outputDestination folder
|
||||
nzbtomedia.makeDir(outputDestination)
|
||||
|
||||
passwordsfile = nzbtomedia.CFG["passwords"]["PassWordFile"]
|
||||
if passwordsfile != "" and os.path.isfile(os.path.normpath(passwordsfile)):
|
||||
passwords = [line.strip() for line in open(os.path.normpath(passwordsfile))]
|
||||
if nzbtomedia.PASSWORDSFILE != "" and os.path.isfile(os.path.normpath(nzbtomedia.PASSWORDSFILE)):
|
||||
passwords = [line.strip() for line in open(os.path.normpath(nzbtomedia.PASSWORDSFILE))]
|
||||
else:
|
||||
passwords = []
|
||||
nzbtomedia.logger.info("Extracting %s to %s" % (filePath, outputDestination))
|
||||
|
|
|
@ -39,9 +39,12 @@ class Section(configobj.Section):
|
|||
if section in key:
|
||||
continue
|
||||
if isinstance(subsections, Section) and subsections.sections:
|
||||
for subsection in subsections:
|
||||
for subsection, options in subsections.items():
|
||||
if subsection in key:
|
||||
continue
|
||||
if key in options:
|
||||
return options[key]
|
||||
|
||||
subsections.pop(subsection)
|
||||
else:
|
||||
if section not in key:
|
||||
|
|
|
@ -459,11 +459,9 @@ def rmDir(dirName):
|
|||
|
||||
def cleanProcDirs():
|
||||
logger.info('Cleaning processing directories ...', 'CLEANDIRS')
|
||||
for section, subsection in nzbtomedia.SUBSECTIONS.items():
|
||||
for section, subsection in nzbtomedia.SECTIONS.items():
|
||||
for category in subsection:
|
||||
if nzbtomedia.CFG[section][category].isenabled():
|
||||
dirNames = getDirs(section, category)
|
||||
for dirName in dirNames:
|
||||
for dirName in nzbtomedia.getDirs(subsection[category]):
|
||||
try:
|
||||
minSize = int(nzbtomedia.CFG[section][category]['minSize'])
|
||||
except:minSize = 0
|
||||
|
@ -603,6 +601,14 @@ def cleanFileName(filename):
|
|||
filename = re.sub("^\[.*\]", "", filename)
|
||||
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):
|
||||
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)\
|
||||
or (audio and fileExt.lower() in nzbtomedia.AUDIOCONTAINER)\
|
||||
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
|
||||
else:
|
||||
return False
|
||||
|
@ -696,33 +702,25 @@ def find_imdbid(dirName, inputName):
|
|||
def extractFiles(src, dst=None):
|
||||
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)
|
||||
fileName, fileExt = os.path.splitext(os.path.basename(inputFile))
|
||||
fullFileName = os.path.basename(inputFile)
|
||||
|
||||
if fileExt in nzbtomedia.COMPRESSEDCONTAINER:
|
||||
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)
|
||||
if dirPath in extracted_folder:
|
||||
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))
|
||||
|
||||
if extracted_folder:
|
||||
for folder in extracted_folder:
|
||||
for inputFile in listMediaFiles(folder):
|
||||
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))
|
||||
try:
|
||||
os.remove(inputFile)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import datetime
|
||||
import re
|
||||
import nzbtomedia
|
||||
from nzbtomedia import nzbToMediaDB
|
||||
from nzbtomedia.nzbToMediaUtil import get_downloadInfo
|
||||
|
@ -7,6 +8,11 @@ from nzbtomedia.nzbToMediaUtil import get_downloadInfo
|
|||
# Initialize the config
|
||||
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']
|
||||
section = nzbtomedia.CFG.findsection('tv').isenabled()
|
||||
print section
|
Loading…
Add table
Add a link
Reference in a new issue