From 8f93dc5354430bb46dc85d89495e6b1899748482 Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 22 Apr 2014 09:01:30 -0700 Subject: [PATCH] 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. --- autoProcessMedia.cfg.spec | 16 ++++++++++++---- nzbtomedia/__init__.py | 3 --- nzbtomedia/nzbToMediaUtil.py | 33 +++++++++++++++------------------ 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 486b34ed..cd1cdb73 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -37,6 +37,8 @@ delete_failed = 0 wait_for = 2 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 remote_path = ##### Set to path where download client places completed downloads locally for this category @@ -60,6 +62,8 @@ Torrent_NoLink = 0 process_method = 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 remote_path = ##### Set to path where download client places completed downloads locally for this category @@ -82,6 +86,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, eg 200mb) + minSize = 200 ##### 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 +108,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, eg 200mb) + minSize = 200 ##### 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 +130,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, eg 200mb) + minSize = 200 ##### 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 +151,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, eg 200mb) + minSize = 200 ##### 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 +199,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 diff --git a/nzbtomedia/__init__.py b/nzbtomedia/__init__.py index 57cb44fb..3980ca36 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -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"]) diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index e504dab3..49b66126 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -117,19 +117,14 @@ def category_search(inputDirectory, inputName, inputCategory, root, categories): 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): - # 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_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 +437,10 @@ def cleanProcDirs(): if nzbtomedia.CFG[section][category].isenabled(): dirNames = get_dirnames(section, category) 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: logger.info( "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: 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): return [] @@ -605,14 +603,13 @@ def listMediaFiles(path, media=True, audio=True, meta=True, archives=True, ignor elif isMediaFile(curFile, media, audio, meta, archives): # 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: os.unlink(fullCurFile) logger.debug('Sample file %s has been removed.' % (curFile)) except:continue - continue - - files.append(fullCurFile) + else: + files.append(fullCurFile) return files