2014-03-10 01:18:05 -04:00
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
#
2014-05-23 08:37:22 -04:00
# This file is part of SickRage.
2014-03-10 01:18:05 -04:00
#
2014-05-23 08:37:22 -04:00
# SickRage is free software: you can redistribute it and/or modify
2014-03-10 01:18:05 -04:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2014-05-23 08:37:22 -04:00
# SickRage is distributed in the hope that it will be useful,
2014-03-10 01:18:05 -04:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2014-05-23 08:37:22 -04:00
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
2014-03-10 01:18:05 -04:00
from __future__ import with_statement
import os
import shutil
import stat
import sickbeard
from sickbeard import postProcessor
from sickbeard import db , helpers , exceptions
from sickbeard import encodingKludge as ek
from sickbeard . exceptions import ex
from sickbeard import logger
2014-07-06 09:11:04 -04:00
from sickbeard . name_parser . parser import NameParser , InvalidNameException , InvalidShowException
2014-03-10 01:18:05 -04:00
from sickbeard import common
from sickbeard import failedProcessor
from lib . unrar2 import RarFile , RarInfo
from lib . unrar2 . rar_exceptions import *
2015-01-12 15:08:18 -05:00
class ProcessResult :
def __init__ ( self ) :
self . result = True
self . output = ' '
2014-03-25 01:57:24 -04:00
2014-06-06 20:44:44 -04:00
def delete_folder ( folder , check_empty = True ) :
# check if it's a folder
if not ek . ek ( os . path . isdir , folder ) :
return False
# check if it isn't TV_DOWNLOAD_DIR
if sickbeard . TV_DOWNLOAD_DIR :
if helpers . real_path ( folder ) == helpers . real_path ( sickbeard . TV_DOWNLOAD_DIR ) :
return False
# check if it's empty folder when wanted checked
if check_empty :
check_files = ek . ek ( os . listdir , folder )
if check_files :
return False
# try deleting folder
try :
logger . log ( u " Deleting folder: " + folder )
shutil . rmtree ( folder )
except ( OSError , IOError ) , e :
logger . log ( u " Warning: unable to delete folder: " + folder + " : " + ex ( e ) , logger . WARNING )
return False
return True
2015-01-12 15:08:18 -05:00
def delete_files ( processPath , notwantedFiles , result ) :
2014-06-06 20:44:44 -04:00
2015-01-12 15:08:18 -05:00
if not result . result :
2014-06-06 20:44:44 -04:00
return
#Delete all file not needed
for cur_file in notwantedFiles :
cur_file_path = ek . ek ( os . path . join , processPath , cur_file )
if not ek . ek ( os . path . isfile , cur_file_path ) :
continue #Prevent error when a notwantedfiles is an associated files
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Deleting file " + cur_file , logger . DEBUG )
2014-06-06 20:44:44 -04:00
#check first the read-only attribute
file_attribute = ek . ek ( os . stat , cur_file_path ) [ 0 ]
if ( not file_attribute & stat . S_IWRITE ) :
# File is read-only, so make it writeable
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Changing ReadOnly Flag for file " + cur_file , logger . DEBUG )
2014-06-06 20:44:44 -04:00
try :
ek . ek ( os . chmod , cur_file_path , stat . S_IWRITE )
except OSError , e :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Cannot change permissions of " + cur_file_path + ' : ' + str ( e . strerror ) ,
2014-06-06 20:44:44 -04:00
logger . DEBUG )
try :
ek . ek ( os . remove , cur_file_path )
except OSError , e :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Unable to delete file " + cur_file + ' : ' + str ( e . strerror ) , logger . DEBUG )
2014-06-06 20:44:44 -04:00
2014-12-16 05:24:06 -05:00
def logHelper ( logMessage , logLevel = logger . INFO ) :
2014-03-10 01:18:05 -04:00
logger . log ( logMessage , logLevel )
return logMessage + u " \n "
2014-03-25 01:57:24 -04:00
2014-03-25 21:42:36 -04:00
def processDir ( dirName , nzbName = None , process_method = None , force = False , is_priority = None , failed = False , type = " auto " ) :
2014-03-10 01:18:05 -04:00
"""
Scans through the files in dirName and processes whatever media files it finds
2014-03-21 04:34:00 -04:00
dirName : The folder name to look in
2014-03-10 01:18:05 -04:00
nzbName : The NZB name which resulted in this folder being downloaded
force : True to postprocess already postprocessed files
failed : Boolean for whether or not the download failed
type : Type of postprocessing auto or manual
"""
2015-01-12 15:08:18 -05:00
result = ProcessResult ( )
2014-03-16 18:57:38 -04:00
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Processing folder " + dirName , logger . DEBUG )
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " TV_DOWNLOAD_DIR: " + sickbeard . TV_DOWNLOAD_DIR , logger . DEBUG )
2014-03-10 01:18:05 -04:00
# if they passed us a real dir then assume it's the one we want
if ek . ek ( os . path . isdir , dirName ) :
dirName = ek . ek ( os . path . realpath , dirName )
2014-05-26 17:32:47 -04:00
# if the client and SickRage are not on the same machine translate the Dir in a network dir
2014-03-10 01:18:05 -04:00
elif sickbeard . TV_DOWNLOAD_DIR and ek . ek ( os . path . isdir , sickbeard . TV_DOWNLOAD_DIR ) \
and ek . ek ( os . path . normpath , dirName ) != ek . ek ( os . path . normpath , sickbeard . TV_DOWNLOAD_DIR ) :
dirName = ek . ek ( os . path . join , sickbeard . TV_DOWNLOAD_DIR , ek . ek ( os . path . abspath , dirName ) . split ( os . path . sep ) [ - 1 ] )
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Trying to use folder " + dirName , logger . DEBUG )
2014-03-10 01:18:05 -04:00
# if we didn't find a real dir then quit
if not ek . ek ( os . path . isdir , dirName ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper (
2014-05-23 08:37:22 -04:00
u " Unable to figure out what folder to process. If your downloader and SickRage aren ' t on the same PC make sure you fill out your TV download dir in the config. " ,
2014-03-25 01:57:24 -04:00
logger . DEBUG )
2015-01-12 15:08:18 -05:00
return result . output
2014-03-10 01:18:05 -04:00
path , dirs , files = get_path_dir_files ( dirName , nzbName , type )
2014-08-11 06:29:28 -04:00
SyncFiles = filter ( helpers . isSyncFile , files )
2014-08-06 09:55:17 -04:00
2014-09-07 06:45:19 -04:00
# Don't post process if files are still being synced and option is activated
if SyncFiles and sickbeard . POSTPONE_IF_SYNC_FILES :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Found temporary sync files, skipping post processing " , logger . WARNING )
return result . output
2014-08-06 09:55:17 -04:00
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " PostProcessing Path: " + path , logger . DEBUG )
result . output + = logHelper ( u " PostProcessing Dirs: " + str ( dirs ) , logger . DEBUG )
2014-03-10 01:18:05 -04:00
rarFiles = filter ( helpers . isRarFile , files )
2015-01-12 15:08:18 -05:00
rarContent = unRAR ( path , rarFiles , force , result )
2014-03-10 01:18:05 -04:00
files + = rarContent
videoFiles = filter ( helpers . isMediaFile , files )
videoInRar = filter ( helpers . isMediaFile , rarContent )
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " PostProcessing Files: " + str ( files ) , logger . DEBUG )
result . output + = logHelper ( u " PostProcessing VideoFiles: " + str ( videoFiles ) , logger . DEBUG )
result . output + = logHelper ( u " PostProcessing RarContent: " + str ( rarContent ) , logger . DEBUG )
result . output + = logHelper ( u " PostProcessing VideoInRar: " + str ( videoInRar ) , logger . DEBUG )
2014-03-10 01:18:05 -04:00
# If nzbName is set and there's more than one videofile in the folder, files will be lost (overwritten).
nzbNameOriginal = nzbName
if len ( videoFiles ) > = 2 :
nzbName = None
if not process_method :
process_method = sickbeard . PROCESS_METHOD
2015-01-12 15:08:18 -05:00
result . result = True
2014-03-10 01:18:05 -04:00
#Don't Link media when the media is extracted from a rar in the same path
if process_method in ( ' hardlink ' , ' symlink ' ) and videoInRar :
2015-01-12 15:08:18 -05:00
result . result = process_media ( path , videoInRar , nzbName , ' move ' , force , is_priority , result )
delete_files ( path , rarContent , result )
2014-03-10 01:18:05 -04:00
for video in set ( videoFiles ) - set ( videoInRar ) :
2015-01-12 15:08:18 -05:00
result . result = process_media ( path , [ video ] , nzbName , process_method , force , is_priority , result )
2014-03-10 01:18:05 -04:00
else :
for video in videoFiles :
2015-01-12 15:08:18 -05:00
result . result = process_media ( path , [ video ] , nzbName , process_method , force , is_priority , result )
2014-03-10 01:18:05 -04:00
#Process Video File in all TV Subdir
2015-01-12 15:08:18 -05:00
for dir in [ x for x in dirs if validateDir ( path , x , nzbNameOriginal , failed , result ) ] :
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
result . result = True
2014-03-10 01:18:05 -04:00
for processPath , processDir , fileList in ek . ek ( os . walk , ek . ek ( os . path . join , path , dir ) , topdown = False ) :
2014-08-11 06:29:28 -04:00
SyncFiles = filter ( helpers . isSyncFile , fileList )
2014-08-06 09:55:17 -04:00
2014-09-07 06:45:19 -04:00
# Don't post process if files are still being synced and option is activated
if SyncFiles and sickbeard . POSTPONE_IF_SYNC_FILES :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Found temporary sync files, skipping post processing " , logger . WARNING )
return result . output
2014-08-06 09:55:17 -04:00
2014-03-10 01:18:05 -04:00
rarFiles = filter ( helpers . isRarFile , fileList )
2015-01-12 15:08:18 -05:00
rarContent = unRAR ( processPath , rarFiles , force , result )
2014-03-10 01:18:05 -04:00
fileList = set ( fileList + rarContent )
videoFiles = filter ( helpers . isMediaFile , fileList )
videoInRar = filter ( helpers . isMediaFile , rarContent )
notwantedFiles = [ x for x in fileList if x not in videoFiles ]
#Don't Link media when the media is extracted from a rar in the same path
if process_method in ( ' hardlink ' , ' symlink ' ) and videoInRar :
2015-01-17 19:01:21 -05:00
process_media ( processPath , videoInRar , nzbName , ' move ' , force , is_priority , result )
2014-03-25 01:57:24 -04:00
process_media ( processPath , set ( videoFiles ) - set ( videoInRar ) , nzbName , process_method , force ,
2015-01-12 15:08:18 -05:00
is_priority , result )
delete_files ( processPath , rarContent , result )
2014-03-10 01:18:05 -04:00
else :
2015-01-12 15:08:18 -05:00
process_media ( processPath , videoFiles , nzbName , process_method , force , is_priority , result )
2014-03-10 01:18:05 -04:00
#Delete all file not needed
2015-01-12 15:08:18 -05:00
if process_method != " move " or not result . result \
2014-03-25 01:57:24 -04:00
or type == " manual " : #Avoid to delete files if is Manual PostProcessing
2014-03-10 01:18:05 -04:00
continue
2014-03-20 06:24:58 -04:00
2015-01-12 15:08:18 -05:00
delete_files ( processPath , notwantedFiles , result )
2014-03-20 06:24:58 -04:00
2014-03-10 01:18:05 -04:00
if process_method == " move " and \
2014-03-25 01:57:24 -04:00
ek . ek ( os . path . normpath , processPath ) != ek . ek ( os . path . normpath ,
sickbeard . TV_DOWNLOAD_DIR ) :
2014-06-06 20:44:44 -04:00
if delete_folder ( processPath , check_empty = False ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Deleted folder: " + processPath , logger . DEBUG )
2014-03-20 06:24:58 -04:00
2015-01-12 15:08:18 -05:00
if result . result :
result . output + = logHelper ( u " Successfully processed " )
2014-05-15 06:27:22 -04:00
else :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Problem(s) during processing " , logger . WARNING )
2014-05-15 06:27:22 -04:00
2015-01-12 15:08:18 -05:00
return result . output
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
def validateDir ( path , dirName , nzbNameOriginal , failed , result ) :
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Processing folder " + dirName , logger . DEBUG )
2014-03-10 01:18:05 -04:00
if ek . ek ( os . path . basename , dirName ) . startswith ( ' _FAILED_ ' ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " The directory name indicates it failed to extract. " , logger . DEBUG )
2014-03-10 01:18:05 -04:00
failed = True
elif ek . ek ( os . path . basename , dirName ) . startswith ( ' _UNDERSIZED_ ' ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " The directory name indicates that it was previously rejected for being undersized. " ,
2014-03-25 01:57:24 -04:00
logger . DEBUG )
2014-03-10 01:18:05 -04:00
failed = True
2014-05-21 12:42:33 -04:00
elif ek . ek ( os . path . basename , dirName ) . upper ( ) . startswith ( ' _UNPACK ' ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " The directory name indicates that this release is in the process of being unpacked. " ,
2014-03-25 01:57:24 -04:00
logger . DEBUG )
2014-05-21 12:42:33 -04:00
return False
2014-03-10 01:18:05 -04:00
if failed :
2015-01-12 15:08:18 -05:00
process_failed ( os . path . join ( path , dirName ) , nzbNameOriginal , result )
2014-03-10 01:18:05 -04:00
return False
2015-02-13 09:00:39 -05:00
if helpers . is_hidden_folder ( os . path . join ( path , dirName ) ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Ignoring hidden folder: " + dirName , logger . DEBUG )
2014-05-21 23:12:15 -04:00
return False
2014-03-10 01:18:05 -04:00
# make sure the dir isn't inside a show dir
2014-06-21 18:46:59 -04:00
myDB = db . DBConnection ( )
sqlResults = myDB . select ( " SELECT * FROM tv_shows " )
2014-06-07 17:32:38 -04:00
2014-03-10 01:18:05 -04:00
for sqlShow in sqlResults :
2014-03-25 01:57:24 -04:00
if dirName . lower ( ) . startswith (
ek . ek ( os . path . realpath , sqlShow [ " location " ] ) . lower ( ) + os . sep ) or dirName . lower ( ) == ek . ek (
os . path . realpath , sqlShow [ " location " ] ) . lower ( ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper (
2014-03-25 01:57:24 -04:00
u " You ' re trying to post process an episode that ' s already been moved to its show dir, skipping " ,
logger . ERROR )
2014-03-10 01:18:05 -04:00
return False
# Get the videofile list for the next checks
allFiles = [ ]
allDirs = [ ]
for processPath , processDir , fileList in ek . ek ( os . walk , ek . ek ( os . path . join , path , dirName ) , topdown = False ) :
allDirs + = processDir
allFiles + = fileList
videoFiles = filter ( helpers . isMediaFile , allFiles )
allDirs . append ( dirName )
2014-03-20 06:24:58 -04:00
2014-03-10 01:18:05 -04:00
#check if the dir have at least one tv video file
for video in videoFiles :
try :
2014-07-18 02:45:48 -04:00
NameParser ( ) . parse ( video , cache_result = False )
2014-03-10 01:18:05 -04:00
return True
2014-07-06 09:11:04 -04:00
except ( InvalidNameException , InvalidShowException ) :
2014-03-10 01:18:05 -04:00
pass
for dir in allDirs :
try :
2014-07-18 02:45:48 -04:00
NameParser ( ) . parse ( dir , cache_result = False )
2014-03-10 01:18:05 -04:00
return True
2014-07-06 09:11:04 -04:00
except ( InvalidNameException , InvalidShowException ) :
2014-03-10 01:18:05 -04:00
pass
if sickbeard . UNPACK :
#Search for packed release
packedFiles = filter ( helpers . isRarFile , allFiles )
for packed in packedFiles :
try :
2014-07-18 02:45:48 -04:00
NameParser ( ) . parse ( packed , cache_result = False )
2014-03-10 01:18:05 -04:00
return True
2014-07-06 09:11:04 -04:00
except ( InvalidNameException , InvalidShowException ) :
2014-03-10 01:18:05 -04:00
pass
return False
2015-01-12 15:08:18 -05:00
def unRAR ( path , rarFiles , force , result ) :
2014-03-10 01:18:05 -04:00
unpacked_files = [ ]
if sickbeard . UNPACK and rarFiles :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Packed Releases detected: " + str ( rarFiles ) , logger . DEBUG )
2014-03-10 01:18:05 -04:00
for archive in rarFiles :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Unpacking archive: " + archive , logger . DEBUG )
2014-03-10 01:18:05 -04:00
try :
rar_handle = RarFile ( os . path . join ( path , archive ) )
# Skip extraction if any file in archive has previously been extracted
skip_file = False
for file_in_archive in [ os . path . basename ( x . filename ) for x in rar_handle . infolist ( ) if not x . isdir ] :
2015-01-12 15:08:18 -05:00
if already_postprocessed ( path , file_in_archive , force , result ) :
result . output + = logHelper (
2014-03-25 01:57:24 -04:00
u " Archive file already post-processed, extraction skipped: " + file_in_archive ,
logger . DEBUG )
2014-03-10 01:18:05 -04:00
skip_file = True
break
if skip_file :
2014-03-20 06:24:58 -04:00
continue
2014-03-25 01:57:24 -04:00
rar_handle . extract ( path = path , withSubpath = False , overwrite = False )
2015-01-08 17:43:05 -05:00
for x in rar_handle . infolist ( ) :
if not x . isdir :
basename = os . path . basename ( x . filename )
if basename not in unpacked_files :
unpacked_files . append ( basename )
2014-03-10 01:18:05 -04:00
del rar_handle
except Exception , e :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Failed Unrar archive " + archive + ' : ' + ex ( e ) , logger . ERROR )
result . result = False
2014-03-25 01:57:24 -04:00
continue
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " UnRar content: " + str ( unpacked_files ) , logger . DEBUG )
2014-03-10 01:18:05 -04:00
return unpacked_files
2015-01-12 15:08:18 -05:00
def already_postprocessed ( dirName , videofile , force , result ) :
2014-03-10 01:18:05 -04:00
if force :
return False
#Needed for accessing DB with a unicode DirName
if not isinstance ( dirName , unicode ) :
dirName = unicode ( dirName , ' utf_8 ' )
# Avoid processing the same dir again if we use a process method <> move
2014-06-21 18:46:59 -04:00
myDB = db . DBConnection ( )
sqlResult = myDB . select ( " SELECT * FROM tv_episodes WHERE release_name = ? " , [ dirName ] )
if sqlResult :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " You ' re trying to post process a dir that ' s already been processed, skipping " ,
2014-06-21 18:46:59 -04:00
logger . DEBUG )
return True
2014-03-10 01:18:05 -04:00
2014-06-24 03:06:39 -04:00
else :
2014-06-07 17:32:38 -04:00
# This is needed for video whose name differ from dirName
if not isinstance ( videofile , unicode ) :
videofile = unicode ( videofile , ' utf_8 ' )
2014-03-10 01:18:05 -04:00
2014-06-07 17:32:38 -04:00
sqlResult = myDB . select ( " SELECT * FROM tv_episodes WHERE release_name = ? " , [ videofile . rpartition ( ' . ' ) [ 0 ] ] )
if sqlResult :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " You ' re trying to post process a video that ' s already been processed, skipping " ,
2014-06-07 17:32:38 -04:00
logger . DEBUG )
return True
2015-01-28 03:56:36 -05:00
2014-06-07 17:32:38 -04:00
#Needed if we have downloaded the same episode @ different quality
2015-01-28 03:56:36 -05:00
#But we need to make sure we check the history of the episode we're going to PP, and not others
np = NameParser ( dirName , tryIndexers = True , convert = True )
try : #if it fails to find any info (because we're doing an unparsable folder (like the TV root dir) it will throw an exception, which we want to ignore
parse_result = np . parse ( dirName )
except : #ignore the exception, because we kind of expected it, but create parse_result anyway so we can perform a check on it.
parse_result = False
pass
search_sql = " SELECT tv_episodes.indexerid, history.resource FROM tv_episodes INNER JOIN history ON history.showid=tv_episodes.showid " #This part is always the same
2014-06-07 17:32:38 -04:00
search_sql + = " WHERE history.season=tv_episodes.season and history.episode=tv_episodes.episode "
2015-01-28 03:56:36 -05:00
#If we find a showid, a season number, and one or more episode numbers then we need to use those in the query
if parse_result and ( parse_result . show . indexerid and parse_result . episode_numbers and parse_result . season_number ) :
search_sql + = " and tv_episodes.showid = ' " + str ( parse_result . show . indexerid ) + " ' and tv_episodes.season = ' " + str ( parse_result . season_number ) + " ' and tv_episodes.episode = ' " + str ( parse_result . episode_numbers [ 0 ] ) + " ' "
2014-06-07 17:32:38 -04:00
search_sql + = " and tv_episodes.status IN ( " + " , " . join ( [ str ( x ) for x in common . Quality . DOWNLOADED ] ) + " ) "
search_sql + = " and history.resource LIKE ? "
sqlResult = myDB . select ( search_sql , [ u ' % ' + videofile ] )
if sqlResult :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " You ' re trying to post process a video that ' s already been processed, skipping " ,
2014-06-07 17:32:38 -04:00
logger . DEBUG )
return True
2014-03-10 01:18:05 -04:00
return False
2015-01-12 15:08:18 -05:00
def process_media ( processPath , videoFiles , nzbName , process_method , force , is_priority , result ) :
2014-03-10 01:18:05 -04:00
2014-06-06 20:44:44 -04:00
processor = None
2014-03-10 01:18:05 -04:00
for cur_video_file in videoFiles :
2015-01-12 15:08:18 -05:00
if already_postprocessed ( processPath , cur_video_file , force , result ) :
2014-03-10 01:18:05 -04:00
continue
cur_video_file_path = ek . ek ( os . path . join , processPath , cur_video_file )
try :
2014-03-25 21:42:36 -04:00
processor = postProcessor . PostProcessor ( cur_video_file_path , nzbName , process_method , is_priority )
2015-01-12 15:08:18 -05:00
result . result = processor . process ( )
2014-03-10 01:18:05 -04:00
process_fail_message = " "
except exceptions . PostProcessingFailed , e :
2015-01-12 15:08:18 -05:00
result . result = False
2014-03-10 01:18:05 -04:00
process_fail_message = ex ( e )
2014-06-06 20:44:44 -04:00
if processor :
2015-01-12 15:08:18 -05:00
result . output + = processor . log
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
if result . result :
result . output + = logHelper ( u " Processing succeeded for " + cur_video_file_path )
2014-03-10 01:18:05 -04:00
else :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Processing failed for " + cur_video_file_path + " : " + process_fail_message ,
2014-03-25 01:57:24 -04:00
logger . WARNING )
2014-03-10 01:18:05 -04:00
#If something fail abort the processing on dir
2015-01-12 15:08:18 -05:00
if not result . result :
2014-03-10 01:18:05 -04:00
break
2014-03-25 01:57:24 -04:00
def get_path_dir_files ( dirName , nzbName , type ) :
2014-06-01 19:39:55 -04:00
path = " "
2014-06-06 20:44:44 -04:00
dirs = [ ]
files = [ ]
2014-05-19 15:20:33 -04:00
2014-03-25 01:57:24 -04:00
if dirName == sickbeard . TV_DOWNLOAD_DIR and not nzbName or type == " manual " : #Scheduled Post Processing Active
2014-03-10 01:18:05 -04:00
#Get at first all the subdir in the dirName
for path , dirs , files in ek . ek ( os . walk , dirName ) :
break
else :
2014-03-25 01:57:24 -04:00
path , dirs = ek . ek ( os . path . split , dirName ) #Script Post Processing
if not nzbName is None and not nzbName . endswith ( ' .nzb ' ) and os . path . isfile (
os . path . join ( dirName , nzbName ) ) : #For single torrent file without Dir
2014-03-10 01:18:05 -04:00
dirs = [ ]
files = [ os . path . join ( dirName , nzbName ) ]
else :
dirs = [ dirs ]
files = [ ]
return path , dirs , files
2014-03-25 01:57:24 -04:00
2015-01-12 15:08:18 -05:00
def process_failed ( dirName , nzbName , result ) :
2014-03-10 01:18:05 -04:00
""" Process a download that did not complete correctly """
if sickbeard . USE_FAILED_DOWNLOADS :
2014-05-19 15:20:33 -04:00
processor = None
2014-03-10 01:18:05 -04:00
try :
processor = failedProcessor . FailedProcessor ( dirName , nzbName )
2015-01-12 15:08:18 -05:00
result . result = processor . process ( )
2014-03-10 01:18:05 -04:00
process_fail_message = " "
except exceptions . FailedProcessingFailed , e :
2015-01-12 15:08:18 -05:00
result . result = False
2014-03-10 01:18:05 -04:00
process_fail_message = ex ( e )
2014-05-19 15:20:33 -04:00
if processor :
2015-01-12 15:08:18 -05:00
result . output + = processor . log
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
if sickbeard . DELETE_FAILED and result . result :
2014-06-06 20:44:44 -04:00
if delete_folder ( dirName , check_empty = False ) :
2015-01-12 15:08:18 -05:00
result . output + = logHelper ( u " Deleted folder: " + dirName , logger . DEBUG )
2014-03-10 01:18:05 -04:00
2015-01-12 15:08:18 -05:00
if result . result :
result . output + = logHelper ( u " Failed Download Processing succeeded: ( " + str ( nzbName ) + " , " + dirName + " ) " )
2014-03-10 01:18:05 -04:00
else :
2015-01-12 15:08:18 -05:00
result . output + = logHelper (
2014-03-25 01:57:24 -04:00
u " Failed Download Processing failed: ( " + str ( nzbName ) + " , " + dirName + " ): " + process_fail_message ,
logger . WARNING )