mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-07-15 01:32:53 -07:00
improve user script media extension handling
This commit is contained in:
parent
9bd61af1bf
commit
bb6eff806e
3 changed files with 12 additions and 11 deletions
|
@ -95,6 +95,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
Torrent_NoLink = int(section.get("Torrent_NoLink", 0))
|
Torrent_NoLink = int(section.get("Torrent_NoLink", 0))
|
||||||
keep_archive = int(section.get("keep_archive", 0))
|
keep_archive = int(section.get("keep_archive", 0))
|
||||||
extract = int(section.get('extract', 0))
|
extract = int(section.get('extract', 0))
|
||||||
|
extensions = section.get('user_script_mediaExtensions', "").lower().split(',')
|
||||||
uniquePath = int(section.get("unique_path", 1))
|
uniquePath = int(section.get("unique_path", 1))
|
||||||
|
|
||||||
if clientAgent != 'manual':
|
if clientAgent != 'manual':
|
||||||
|
@ -138,9 +139,9 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
|
||||||
if extract == 1:
|
if extract == 1:
|
||||||
inputFiles = core.listMediaFiles(inputDirectory, archives=False)
|
inputFiles = core.listMediaFiles(inputDirectory, archives=False, other=True, otherext=extensions)
|
||||||
else:
|
else:
|
||||||
inputFiles = core.listMediaFiles(inputDirectory)
|
inputFiles = core.listMediaFiles(inputDirectory, other=True, otherext=extensions)
|
||||||
logger.debug("Found {0} files in {1}".format(len(inputFiles), inputDirectory))
|
logger.debug("Found {0} files in {1}".format(len(inputFiles), inputDirectory))
|
||||||
for inputFile in inputFiles:
|
for inputFile in inputFiles:
|
||||||
filePath = os.path.dirname(inputFile)
|
filePath = os.path.dirname(inputFile)
|
||||||
|
|
|
@ -11,7 +11,7 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
final_result = 0 # start at 0.
|
final_result = 0 # start at 0.
|
||||||
num_files = 0
|
num_files = 0
|
||||||
try:
|
try:
|
||||||
core.USER_SCRIPT_MEDIAEXTENSIONS = settings["user_script_mediaExtensions"]
|
core.USER_SCRIPT_MEDIAEXTENSIONS = settings["user_script_mediaExtensions"].lower()
|
||||||
if isinstance(core.USER_SCRIPT_MEDIAEXTENSIONS, str):
|
if isinstance(core.USER_SCRIPT_MEDIAEXTENSIONS, str):
|
||||||
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',')
|
core.USER_SCRIPT_MEDIAEXTENSIONS = core.USER_SCRIPT_MEDIAEXTENSIONS.split(',')
|
||||||
except:
|
except:
|
||||||
|
@ -51,7 +51,7 @@ def external_script(outputDestination, torrentName, torrentLabel, settings):
|
||||||
filePath = core.os.path.join(dirpath, file)
|
filePath = core.os.path.join(dirpath, file)
|
||||||
fileName, fileExtension = os.path.splitext(file)
|
fileName, fileExtension = os.path.splitext(file)
|
||||||
|
|
||||||
if fileExtension in core.USER_SCRIPT_MEDIAEXTENSIONS or "ALL" in core.USER_SCRIPT_MEDIAEXTENSIONS:
|
if fileExtension in core.USER_SCRIPT_MEDIAEXTENSIONS or "all" in core.USER_SCRIPT_MEDIAEXTENSIONS:
|
||||||
num_files += 1
|
num_files += 1
|
||||||
if core.USER_SCRIPT_RUNONCE == 1 and num_files > 1: # we have already run once, so just continue to get number of files.
|
if core.USER_SCRIPT_RUNONCE == 1 and num_files > 1: # we have already run once, so just continue to get number of files.
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -960,7 +960,7 @@ def is_archive_file(filename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
|
def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True, other=False, otherext=[]):
|
||||||
fileName, fileExt = os.path.splitext(mediafile)
|
fileName, fileExt = os.path.splitext(mediafile)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -969,22 +969,22 @@ def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
|
||||||
return False
|
return False
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if (media and fileExt.lower() in core.MEDIACONTAINER) \
|
if (media and fileExt.lower() in core.MEDIACONTAINER) \
|
||||||
or (audio and fileExt.lower() in core.AUDIOCONTAINER) \
|
or (audio and fileExt.lower() in core.AUDIOCONTAINER) \
|
||||||
or (meta and fileExt.lower() in core.METACONTAINER) \
|
or (meta and fileExt.lower() in core.METACONTAINER) \
|
||||||
or (archives and is_archive_file(mediafile)):
|
or (archives and is_archive_file(mediafile)) \
|
||||||
|
or (other and (fileExt.lower() in otherext or 'all' in otherext)):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, meta=True, archives=True):
|
def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, meta=True, archives=True, other=False, otherext=[]):
|
||||||
files = []
|
files = []
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
if os.path.isfile(path): # Single file downloads.
|
if os.path.isfile(path): # Single file downloads.
|
||||||
curFile = os.path.split(path)[1]
|
curFile = os.path.split(path)[1]
|
||||||
if isMediaFile(curFile, media, audio, meta, archives):
|
if isMediaFile(curFile, media, audio, meta, archives, other, otherext):
|
||||||
# Optionally ignore sample files
|
# Optionally ignore sample files
|
||||||
if is_sample(path) or not is_minSize(path, minSize):
|
if is_sample(path) or not is_minSize(path, minSize):
|
||||||
if delete_ignored == 1:
|
if delete_ignored == 1:
|
||||||
|
@ -1004,9 +1004,9 @@ def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, me
|
||||||
|
|
||||||
# if it's a folder do it recursively
|
# if it's a folder do it recursively
|
||||||
if os.path.isdir(fullCurFile) and not curFile.startswith('.'):
|
if os.path.isdir(fullCurFile) and not curFile.startswith('.'):
|
||||||
files += listMediaFiles(fullCurFile, minSize, delete_ignored, media, audio, meta, archives)
|
files += listMediaFiles(fullCurFile, minSize, delete_ignored, media, audio, meta, archives, other, otherext)
|
||||||
|
|
||||||
elif isMediaFile(curFile, media, audio, meta, archives):
|
elif isMediaFile(curFile, media, audio, meta, archives, other, otherext):
|
||||||
# Optionally ignore sample files
|
# Optionally ignore sample files
|
||||||
if is_sample(fullCurFile) or not is_minSize(fullCurFile, minSize):
|
if is_sample(fullCurFile) or not is_minSize(fullCurFile, minSize):
|
||||||
if delete_ignored == 1:
|
if delete_ignored == 1:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue