diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index cd1cdb73..486b34ed 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -37,8 +37,6 @@ 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 @@ -62,8 +60,6 @@ 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 @@ -86,8 +82,6 @@ # 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 @@ -108,8 +102,6 @@ # 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 @@ -130,8 +122,6 @@ # 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 @@ -151,8 +141,6 @@ # 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 @@ -199,6 +187,10 @@ 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 3980ca36..57cb44fb 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -268,6 +268,9 @@ 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 49b66126..e504dab3 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -117,14 +117,19 @@ 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): - # Ignore 'sample' in files - if re.search('(^|[\W_])sample\d*[\W_]', inputName.lower()): - 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 copy_link(filePath, targetDirectory, useLink, outputDestination): if os.path.isfile(targetDirectory): @@ -437,10 +442,7 @@ def cleanProcDirs(): if nzbtomedia.CFG[section][category].isenabled(): dirNames = get_dirnames(section, category) for dirName in dirNames: - try: - minSize = nzbtomedia.CFG[section][category]['minSize'] - except:minSize = 200 - num_files = len(listMediaFiles(dirName, minSize=minSize)) + num_files = len(listMediaFiles(dirName)) if num_files > 0: logger.info( "Directory %s still contains %s unprocessed file(s), skipping ..." % (dirName, num_files), @@ -589,7 +591,7 @@ def isMediaFile(mediafile, media=True, audio=True, meta=True, archives=True): else: return False -def listMediaFiles(path, minSize=200, media=True, audio=True, meta=True, archives=True, ignoreSample=True): +def listMediaFiles(path, media=True, audio=True, meta=True, archives=True, ignoreSample=True): if not dir or not os.path.isdir(path): return [] @@ -603,13 +605,14 @@ def listMediaFiles(path, minSize=200, media=True, audio=True, meta=True, archive elif isMediaFile(curFile, media, audio, meta, archives): # Optionally ignore sample files - if is_sample(fullCurFile) or not is_minSize(fullCurFile, minSize): + 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 - else: - files.append(fullCurFile) + continue + + files.append(fullCurFile) return files