Fixes issue #332 with is_sample problem.

This commit is contained in:
echel0n 2014-04-20 08:19:26 -07:00
commit 2391f4a5de
4 changed files with 28 additions and 28 deletions

View file

@ -2,8 +2,7 @@ import errno
import os import os
import platform import platform
import nzbtomedia import nzbtomedia
from subprocess import call, Popen from subprocess import call
from lib import guessit
from nzbtomedia import logger from nzbtomedia import logger
from nzbToMediaUtil import listMediaFiles from nzbToMediaUtil import listMediaFiles

View file

@ -4,7 +4,7 @@ import nzbtomedia
from lib import requests from lib import requests
from nzbtomedia.Transcoder import Transcoder from nzbtomedia.Transcoder import Transcoder
from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions
from nzbtomedia.nzbToMediaUtil import convert_to_ascii, delete, find_imdbid, find_download, joinPath from nzbtomedia.nzbToMediaUtil import convert_to_ascii, rmDir, find_imdbid, find_download, joinPath
from nzbtomedia import logger from nzbtomedia import logger
@ -96,7 +96,7 @@ class autoProcessMovie:
port = nzbtomedia.CFG[section][inputCategory]["port"] port = nzbtomedia.CFG[section][inputCategory]["port"]
apikey = nzbtomedia.CFG[section][inputCategory]["apikey"] apikey = nzbtomedia.CFG[section][inputCategory]["apikey"]
method = nzbtomedia.CFG[section][inputCategory]["method"] method = nzbtomedia.CFG[section][inputCategory]["method"]
delete_failed = int(nzbtomedia.CFG[section][inputCategory]["delete_failed"]) rmDir_failed = int(nzbtomedia.CFG[section][inputCategory]["rmDir_failed"])
wait_for = int(nzbtomedia.CFG[section][inputCategory]["wait_for"]) wait_for = int(nzbtomedia.CFG[section][inputCategory]["wait_for"])
try: try:
@ -186,9 +186,9 @@ class autoProcessMovie:
else: else:
logger.postprocess("FAILED DOWNLOAD DETECTED FOR %s" % (nzbName), section) logger.postprocess("FAILED DOWNLOAD DETECTED FOR %s" % (nzbName), section)
if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName: if rmDir_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName:
logger.postprocess("Deleting failed files and folder %s" % dirName, section) logger.postprocess("Deleting failed files and folder %s" % dirName, section)
delete(dirName) rmDir(dirName)
if not download_id: if not download_id:
logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % nzbName, logger.error("Could not find a downloaded movie in the database matching %s, exiting!" % nzbName,

View file

@ -5,7 +5,7 @@ from lib import requests
from nzbtomedia.Transcoder import Transcoder from nzbtomedia.Transcoder import Transcoder
from nzbtomedia.nzbToMediaAutoFork import autoFork from nzbtomedia.nzbToMediaAutoFork import autoFork
from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions
from nzbtomedia.nzbToMediaUtil import convert_to_ascii, is_sample, flatten, delete, joinPath from nzbtomedia.nzbToMediaUtil import convert_to_ascii, flatten, rmDir, joinPath, listMediaFiles
from nzbtomedia import logger from nzbtomedia import logger
class autoProcessTV: class autoProcessTV:
@ -40,9 +40,9 @@ class autoProcessTV:
except: except:
web_root = "" web_root = ""
try: try:
delete_failed = int(nzbtomedia.CFG[section][inputCategory]["delete_failed"]) rmDir_failed = int(nzbtomedia.CFG[section][inputCategory]["rmDir_failed"])
except: except:
delete_failed = 0 rmDir_failed = 0
try: try:
nzbExtractionBy = nzbtomedia.CFG[section][inputCategory]["nzbExtractionBy"] nzbExtractionBy = nzbtomedia.CFG[section][inputCategory]["nzbExtractionBy"]
except: except:
@ -76,17 +76,15 @@ class autoProcessTV:
nzbName, dirName = convert_to_ascii(nzbName, dirName) nzbName, dirName = convert_to_ascii(nzbName, dirName)
# Now check if tv files exist in destination. Eventually extraction may be done here if nzbExtractionBy == TorrentToMedia # Now check if tv files exist in destination. Eventually extraction may be done here if nzbExtractionBy == TorrentToMedia
video = int(0) video = 0
for dirpath, dirnames, filenames in os.walk(dirName): for dirFile in listMediaFiles(dirName):
for file in filenames: fullFileName = os.path.basename(dirFile)
filePath = joinPath(dirpath, file) fileName, fileExt = os.path.splitext(fullFileName)
fileExtension = os.path.splitext(file)[1]
if fileExtension in nzbtomedia.MEDIACONTAINER: # If the file is a video file if fileExt in nzbtomedia.MEDIACONTAINER:
if is_sample(filePath, nzbName, nzbtomedia.MINSAMPLESIZE, nzbtomedia.SAMPLEIDS): logger.debug("Found media file: %s" % (fullFileName))
logger.debug("Removing sample file: %s" % (filePath), section) video += 1
os.unlink(filePath) # remove samples
else:
video = video + 1
if video > 0: # Check that a video exists. if not, assume failed. if video > 0: # Check that a video exists. if not, assume failed.
flatten(dirName) # to make sure SickBeard can find the video (not in sub-folder) flatten(dirName) # to make sure SickBeard can find the video (not in sub-folder)
elif clientAgent == "manual": elif clientAgent == "manual":
@ -94,7 +92,7 @@ class autoProcessTV:
return 0 # Success (as far as this script is concerned) return 0 # Success (as far as this script is concerned)
else: else:
logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section) logger.warning("No media files found in directory %s. Processing this as a failed download" % (dirName), section)
status = int(1) status = 1
failed = True failed = True
# configure SB params to pass # configure SB params to pass
@ -120,7 +118,7 @@ class autoProcessTV:
else: else:
del fork_params[param] del fork_params[param]
# delete any unused params so we don't pass them to SB by mistake # rmDir any unused params so we don't pass them to SB by mistake
[fork_params.pop(k) for k,v in fork_params.items() if v is None] [fork_params.pop(k) for k,v in fork_params.items() if v is None]
if status == 0: if status == 0:
@ -130,9 +128,9 @@ class autoProcessTV:
logger.postprocess("FAILED: The download failed. Sending 'failed' process request to %s branch" % (fork), section) logger.postprocess("FAILED: The download failed. Sending 'failed' process request to %s branch" % (fork), section)
else: else:
logger.postprocess("FAILED: The download failed. %s branch does not handle failed downloads. Nothing to process" % (fork), section) logger.postprocess("FAILED: The download failed. %s branch does not handle failed downloads. Nothing to process" % (fork), section)
if delete_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName: if rmDir_failed and os.path.isdir(dirName) and not os.path.dirname(dirName) == dirName:
logger.postprocess("Deleting failed files and folder %s" % (dirName), section) logger.postprocess("Deleting failed files and folder %s" % (dirName), section)
delete(dirName) rmDir(dirName)
return 0 # Success (as far as this script is concerned) return 0 # Success (as far as this script is concerned)
if status == 0 and nzbtomedia.TRANSCODE == 1: # only transcode successful downlaods if status == 0 and nzbtomedia.TRANSCODE == 1: # only transcode successful downlaods
@ -170,7 +168,7 @@ class autoProcessTV:
for line in r.iter_lines(): for line in r.iter_lines():
if line: logger.postprocess("%s" % (line), section) if line: logger.postprocess("%s" % (line), section)
if status != 0 and delete_failed and not os.path.dirname(dirName) == dirName: if status != 0 and rmDir_failed and not os.path.dirname(dirName) == dirName:
logger.postprocess("Deleting failed files and folder %s" % (dirName),section) logger.postprocess("Deleting failed files and folder %s" % (dirName),section)
delete(dirName) rmDir(dirName)
return 0 # Success return 0 # Success

View file

@ -428,14 +428,13 @@ def get_dirnames(section, subsections=None):
return list(set(dirNames)) return list(set(dirNames))
def delete(dirName): def rmDir(dirName):
logger.info("Deleting %s" % (dirName)) logger.info("Deleting %s" % (dirName))
try: try:
shutil.rmtree(dirName, True) shutil.rmtree(dirName, True)
except: except:
logger.error("Unable to delete folder %s" % (dirName)) logger.error("Unable to delete folder %s" % (dirName))
def cleanup_directories(inputCategory, processCategories, result, directory): def cleanup_directories(inputCategory, processCategories, result, directory):
if inputCategory in processCategories and result == 0 and os.path.isdir(directory): if inputCategory in processCategories and result == 0 and os.path.isdir(directory):
num_files_new = int(0) num_files_new = int(0)
@ -612,6 +611,10 @@ def listMediaFiles(path, ignoreSample=True):
elif isMediaFile(curFile): elif isMediaFile(curFile):
# Optionally ignore sample files # Optionally ignore sample files
if ignoreSample and is_sample(fullCurFile, nzbtomedia.MINSAMPLESIZE, nzbtomedia.SAMPLEIDS): 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
continue continue
files.append(fullCurFile) files.append(fullCurFile)