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 and removed from disk, Default size is 200MB.

This commit is contained in:
echel0n 2014-04-22 09:01:30 -07:00
commit 8f93dc5354
3 changed files with 27 additions and 25 deletions

View file

@ -37,6 +37,8 @@
delete_failed = 0 delete_failed = 0
wait_for = 2 wait_for = 2
extract = 1 extract = 1
# Set this to minimum required size to consider a media file valid (in MB, eg 200mb)
minSize = 200
##### Set to path where completed downloads are found on remote server for this category ##### Set to path where completed downloads are found on remote server for this category
remote_path = remote_path =
##### Set to path where download client places completed downloads locally for this category ##### Set to path where download client places completed downloads locally for this category
@ -60,6 +62,8 @@
Torrent_NoLink = 0 Torrent_NoLink = 0
process_method = process_method =
extract = 1 extract = 1
# Set this to minimum required size to consider a media file valid (in MB, eg 200mb)
minSize = 200
##### Set to path where completed downloads are found on remote server for this category ##### Set to path where completed downloads are found on remote server for this category
remote_path = remote_path =
##### Set to path where download client places completed downloads locally for this category ##### Set to path where download client places completed downloads locally for this category
@ -82,6 +86,8 @@
# Enable/Disable linking for Torrents # Enable/Disable linking for Torrents
Torrent_NoLink = 0 Torrent_NoLink = 0
extract = 1 extract = 1
# Set this to minimum required size to consider a media file valid (in MB, eg 200mb)
minSize = 200
##### Set to path where completed downloads are found on remote server for this category ##### Set to path where completed downloads are found on remote server for this category
remote_path = remote_path =
##### Set to path where download client places completed downloads locally for this category ##### Set to path where download client places completed downloads locally for this category
@ -102,6 +108,8 @@
# Enable/Disable linking for Torrents # Enable/Disable linking for Torrents
Torrent_NoLink = 0 Torrent_NoLink = 0
extract = 1 extract = 1
# Set this to minimum required size to consider a media file valid (in MB, eg 200mb)
minSize = 200
##### Set to path where completed downloads are found on remote server for this category ##### Set to path where completed downloads are found on remote server for this category
remote_path = remote_path =
##### Set to path where download client places completed downloads locally for this category ##### Set to path where download client places completed downloads locally for this category
@ -122,6 +130,8 @@
# Enable/Disable linking for Torrents # Enable/Disable linking for Torrents
Torrent_NoLink = 0 Torrent_NoLink = 0
extract = 1 extract = 1
# Set this to minimum required size to consider a media file valid (in MB, eg 200mb)
minSize = 200
##### Set to path where completed downloads are found on remote server for this category ##### Set to path where completed downloads are found on remote server for this category
remote_path = remote_path =
##### Set to path where download client places completed downloads locally for this category ##### Set to path where download client places completed downloads locally for this category
@ -141,6 +151,8 @@
# Enable/Disable linking for Torrents # Enable/Disable linking for Torrents
Torrent_NoLink = 0 Torrent_NoLink = 0
extract = 1 extract = 1
# Set this to minimum required size to consider a media file valid (in MB, eg 200mb)
minSize = 200
##### Set to path where completed downloads are found on remote server for this category ##### Set to path where completed downloads are found on remote server for this category
remote_path = remote_path =
##### Set to path where download client places completed downloads locally for this category ##### Set to path where download client places completed downloads locally for this category
@ -187,10 +199,6 @@
mediaExtensions = .mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso,.m4v mediaExtensions = .mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso,.m4v
audioExtensions = .mp3, .aac, .ogg, .ape, .m4a, .asf, .wma, .flac audioExtensions = .mp3, .aac, .ogg, .ape, .m4a, .asf, .wma, .flac
metaExtensions = .nfo,.sub,.srt,.jpg,.gif 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] [Transcoder]
transcode = 0 transcode = 0

View file

@ -268,9 +268,6 @@ def initialize(section=None):
if isinstance(AUDIOCONTAINER, str): AUDIOCONTAINER = AUDIOCONTAINER.split(',') if isinstance(AUDIOCONTAINER, str): AUDIOCONTAINER = AUDIOCONTAINER.split(',')
if isinstance(METACONTAINER, str): METACONTAINER = METACONTAINER.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"]) TRANSCODE = int(CFG["Transcoder"]["transcode"])
DUPLICATE = int(CFG["Transcoder"]["duplicate"]) DUPLICATE = int(CFG["Transcoder"]["duplicate"])
IGNOREEXTENSIONS = (CFG["Transcoder"]["ignoreExtensions"]) IGNOREEXTENSIONS = (CFG["Transcoder"]["ignoreExtensions"])

View file

@ -117,19 +117,14 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories):
return inputDirectory, inputName, inputCategory, root, single return inputDirectory, inputName, inputCategory, root, single
def is_minSize(inputName, minSize):
if os.path.getsize(inputName) < minSize * 1048576:
return True
def is_sample(inputName, minSampleSize, SampleIDs): def is_sample(inputName):
# 200 MB in bytes # Ignore 'sample' in files
SIZE_CUTOFF = minSampleSize * 1024 * 1024 if re.search('(^|[\W_])sample\d*[\W_]', inputName.lower()):
if os.path.getsize(inputName) < SIZE_CUTOFF: return True
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 copy_link(filePath, targetDirectory, useLink, outputDestination): def copy_link(filePath, targetDirectory, useLink, outputDestination):
if os.path.isfile(targetDirectory): if os.path.isfile(targetDirectory):
@ -442,7 +437,10 @@ def cleanProcDirs():
if nzbtomedia.CFG[section][category].isenabled(): if nzbtomedia.CFG[section][category].isenabled():
dirNames = get_dirnames(section, category) dirNames = get_dirnames(section, category)
for dirName in dirNames: for dirName in dirNames:
num_files = len(listMediaFiles(dirName)) try:
minSize = nzbtomedia.CFG[section][category]['minSize']
except:minSize = 200
num_files = len(listMediaFiles(dirName, minSize=minSize))
if num_files > 0: if num_files > 0:
logger.info( logger.info(
"Directory %s still contains %s unprocessed file(s), skipping ..." % (dirName, num_files), "Directory %s still contains %s unprocessed file(s), skipping ..." % (dirName, num_files),
@ -591,7 +589,7 @@ def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True):
else: else:
return False return False
def listMediaFiles(path, media=True, audio=True, meta=True, archives=True, ignoreSample=True): def listMediaFiles(path, minSize=200, media=True, audio=True, meta=True, archives=True, ignoreSample=True):
if not dir or not os.path.isdir(path): if not dir or not os.path.isdir(path):
return [] return []
@ -605,14 +603,13 @@ def listMediaFiles(path, media=True, audio=True, meta=True, archives=True, ignor
elif isMediaFile(curFile, media, audio, meta, archives): elif isMediaFile(curFile, media, audio, meta, archives):
# Optionally ignore sample files # Optionally ignore sample files
if ignoreSample and is_sample(fullCurFile, nzbtomedia.MINSAMPLESIZE, nzbtomedia.SAMPLEIDS): if is_sample(fullCurFile) or not is_minSize(fullCurFile, minSize):
try: try:
os.unlink(fullCurFile) os.unlink(fullCurFile)
logger.debug('Sample file %s has been removed.' % (curFile)) logger.debug('Sample file %s has been removed.' % (curFile))
except:continue except:continue
continue else:
files.append(fullCurFile)
files.append(fullCurFile)
return files return files