Added minSize option to all category subsections, this allows you to set a minimum size requirement for downloads to pass to be considered a valid media file and if they fail this check there ignored

Added delete_ignored option to all category sections, this allows automatic deleteing of ignored files (samples and invalid media files)
This commit is contained in:
echel0n 2014-04-22 09:56:11 -07:00
commit 868ac210e9
3 changed files with 60 additions and 33 deletions

View file

@ -37,6 +37,10 @@
delete_failed = 0
wait_for = 2
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleteing ignored files (samples and invalid media files)
delete_ignored = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
@ -60,6 +64,10 @@
Torrent_NoLink = 0
process_method =
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleteing ignored files (samples and invalid media files)
delete_ignored = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
@ -82,6 +90,10 @@
# Enable/Disable linking for Torrents
Torrent_NoLink = 0
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleteing ignored files (samples and invalid media files)
delete_ignored = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
@ -102,6 +114,10 @@
# Enable/Disable linking for Torrents
Torrent_NoLink = 0
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleteing ignored files (samples and invalid media files)
delete_ignored = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
@ -122,6 +138,10 @@
# Enable/Disable linking for Torrents
Torrent_NoLink = 0
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
# Enable/Disable deleteing ignored files (samples and invalid media files)
delete_ignored = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
@ -141,6 +161,8 @@
# Enable/Disable linking for Torrents
Torrent_NoLink = 0
extract = 1
# Set this to minimum required size to consider a media file valid (in MB)
minSize = 0
##### Set to path where completed downloads are found on remote server for this category
remote_path =
##### Set to path where download client places completed downloads locally for this category
@ -187,10 +209,6 @@
mediaExtensions = .mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso,.m4v
audioExtensions = .mp3, .aac, .ogg, .ape, .m4a, .asf, .wma, .flac
metaExtensions = .nfo,.sub,.srt,.jpg,.gif
###### minSampleSize - Minimum required size to consider a media file not a sample file (in MB, eg 200mb)
minSampleSize = 200
###### SampleIDs - a list of common sample identifiers. Use SizeOnly to ignore this and delete all media files less than minSampleSize
SampleIDs = sample,-s.
[Transcoder]
transcode = 0

View file

@ -268,9 +268,6 @@ def initialize(section=None):
if isinstance(AUDIOCONTAINER, str): AUDIOCONTAINER = AUDIOCONTAINER.split(',')
if isinstance(METACONTAINER, str): METACONTAINER = METACONTAINER.split(',')
MINSAMPLESIZE = int(CFG["Extensions"]["minSampleSize"]) # 200 (in MB)
SAMPLEIDS = CFG["Extensions"]["SampleIDs"]
TRANSCODE = int(CFG["Transcoder"]["transcode"])
DUPLICATE = int(CFG["Transcoder"]["duplicate"])
IGNOREEXTENSIONS = (CFG["Transcoder"]["ignoreExtensions"])
@ -293,12 +290,12 @@ def initialize(section=None):
if not (os.path.isfile(FFMPEG)): # problem
FFMPEG = None
logger.warning("Failed to locate %s, transcoding disabled!" % (FFMPEG))
logger.warning("Failed to locate ffmpeg.exe, transcoding disabled!")
logger.warning("Install ffmpeg with x264 support to enable this feature ...")
if not (os.path.isfile(FFPROBE)): # problem
FFPROBE = None
logger.warning("Failed to locate %s, video corruption detection disabled!" % (FFPROBE))
logger.warning("Failed to locate ffprobe.exe, video corruption detection disabled!")
logger.warning("Install ffmpeg with x264 support to enable this feature ...")
else:

View file

@ -117,19 +117,28 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
return inputDirectory, inputName, inputCategory, root, single
def getDirSize(inputPath):
from functools import partial
prepend = partial(os.path.join, inputPath)
return sum([(os.path.getsize(f) if os.path.isfile(f) else getDirSize(f)) for f in map(prepend, os.listdir(inputPath))])
def is_sample(inputName, minSampleSize, SampleIDs):
# 200 MB in bytes
SIZE_CUTOFF = minSampleSize * 1024 * 1024
if os.path.getsize(inputName) < SIZE_CUTOFF:
if 'SizeOnly' in SampleIDs:
return True
# Ignore 'sample' in files
for ident in SampleIDs:
if re.search(ident,inputName,flags=re.I):
return True
# Return False if none of these were met.
return False
def is_minSize(inputName, minSize):
fileName, fileExt = os.path.splitext(os.path.basename(inputName))
# audio files we need to check directory size not file size
inputSize = os.path.getsize(inputName)
if fileExt in (nzbtomedia.AUDIOCONTAINER):
inputSize = getDirSize(os.path.dirname(inputName))
# Ignore files under a certain size
if inputSize < minSize * 1048576:
return True
def is_sample(inputName):
# Ignore 'sample' in files
if re.search('(^|[\W_])sample\d*[\W_]', inputName.lower()):
return True
def copy_link(filePath, targetDirectory, useLink, outputDestination):
if os.path.isfile(targetDirectory):
@ -442,7 +451,13 @@ def cleanProcDirs():
if nzbtomedia.CFG[section][category].isenabled():
dirNames = get_dirnames(section, category)
for dirName in dirNames:
num_files = len(listMediaFiles(dirName))
try:
minSize = int(nzbtomedia.CFG[section][category]['minSize'])
except:minSize = 0
try:
delete_ignored = int(nzbtomedia.CFG[section][category]['delete_ignored'])
except:delete_ignored = 0
num_files = len(listMediaFiles(dirName, minSize=minSize, delete_ignored=delete_ignored))
if num_files > 0:
logger.info(
"Directory %s still contains %s unprocessed file(s), skipping ..." % (dirName, num_files),
@ -579,10 +594,6 @@ def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
if fileName.startswith('._'):
return False
if re.search('extras?$', fileName, re.I):
logger.info("Ignoring extras file: %s " % (mediafile))
return False
if (media and fileExt.lower() in nzbtomedia.MEDIACONTAINER)\
or (audio and fileExt.lower() in nzbtomedia.AUDIOCONTAINER)\
or (meta and fileExt.lower() in nzbtomedia.METACONTAINER)\
@ -591,7 +602,7 @@ def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
else:
return False
def listMediaFiles(path, media=True, audio=True, meta=True, archives=True, ignoreSample=True):
def listMediaFiles(path, minSize=0, delete_ignored=0, media=True, audio=True, meta=True, archives=True):
if not dir or not os.path.isdir(path):
return []
@ -601,15 +612,16 @@ def listMediaFiles(path, media=True, audio=True, meta=True, archives=True, ignor
# if it's a folder do it recursively
if os.path.isdir(fullCurFile) and not curFile.startswith('.') and not curFile == 'Extras':
files += listMediaFiles(fullCurFile, media, audio, meta, archives)
files += listMediaFiles(fullCurFile, minSize, delete_ignored, media, audio, meta, archives)
elif isMediaFile(curFile, media, audio, meta, archives):
# Optionally ignore sample files
if ignoreSample and is_sample(fullCurFile, nzbtomedia.MINSAMPLESIZE, nzbtomedia.SAMPLEIDS):
try:
os.unlink(fullCurFile)
logger.debug('Sample file %s has been removed.' % (curFile))
except:continue
if is_sample(fullCurFile) or not is_minSize(fullCurFile, minSize):
if delete_ignored == 1:
try:
os.unlink(fullCurFile)
logger.debug('Ignored file %s has been removed ...' % (curFile))
except:pass
continue
files.append(fullCurFile)